2_Questions_4-1

2_Questions_4-1 - CIS 15AG Questions Chapter 4: Functions 1...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 15AG Questions Chapter 4: Functions 1. Why do we need functions in a program? 1. 2. 2. How complex should functions be? 3. What is the output displayed by the following program fragment? // Local Declarations int a; int b; double c; double d; // Statements a = 25; c = sqrt( a ); printf("%3d %6.2f\n", a, c ); Answer: d = -7.4; printf("%5.2f %5.2f", d, fabs(d)); printf("%5.2f %5.2f\n", floor(d), ceil(d)); Answer: b = rand() % 10; printf("%5d\n", b ); Answer: 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CIS 15AG Questions Chapter 4: Functions 4. Review the following program. a. Draw the structure chart. b. Circle a function definition. (Circle and label it, as it is shown below) c. Circle a formal parameter. d. Circle a function call. e. Circle an actual parameter. f. Circle a prototype declaration. g. Circle a local variable. h. Predict the output. i. Circle a preprocessor directive. #include <stdio.h> int fun ( int ); int main( void ) { int a; int b; b = 4; a = fun(b+1); printf"%5d, %5d\n", a, b); a = 1; a = fun(a); printf"%5d, %5d\n", a, b); return 0; } /*======== fun ========*/ int fun ( int b ) { int a; b = 10 * b; a = b + 1; return a + 2; } 2 (i) Answer to 12.h:
Background image of page 2
CIS 15AG Questions Chapter 4: Functions 5. Suppose integer variables a, b, and c, have values 20, 30, and 36 respectively. Using the function:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/02/2011 for the course CIS 15BG taught by Professor Staff during the Spring '10 term at DeAnza College.

Page1 / 9

2_Questions_4-1 - CIS 15AG Questions Chapter 4: Functions 1...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online