Homework Assigment 1



Structure of a C Program and Functions

1. Given the following pseudocode, write a program that executes it. Use floating-point types for all values.

Algorithm Problem1

1. Read x

2. Read y

3. Compute p = x * y

4. Compute s = x + y

5. Total = s2 + p * (s – x) * (p + y)

6. Print the total

End Problem1

2. If originally, x = 2, y = 3 and z = 1, what is the value of each of the following expressions?

a) printf( “ the value is : %d “, x++ + y++ );

b) printf( “ the value is : %d “, ++x - --z );

c) printf( “ the value is : %d “, --x + y++ );

d) printf( “ the value is : %d “, x-- + x-- - y-- );

e) printf( “ the value is : %d “, x + y-- - x + x++ - --y );

f) printf( “ the value is : %d “, x + 2 / 6 + y );

g) printf( “ the value is : %d “, y - 3 * z + 2);

h) printf( “ the value is : %d “, z - (x + z ) % 2 + 4);

i) printf( “ the value is : %d “, x - 2 * ( 3 + z) + y );

j) printf( “ the value is : %d “, y % 2 * z % x );

3. Find any errors in the following function definition:

int ( fun( int x, y )

{

int z;



return z;

}

4. Find any errors in the following function calls:

a) void fun();

b) fun(void);

c) int fun( int x, int y );

d) fun();

5. Write a function to convert inches into centimeters (one inch is 2.54 centimeters). Then write a program that prompts the user to input a measure in inches calls the conversion function and prints out the measurement in centimeters. Hand in a flowchart for this as well. Make sure that this program can be executed without errors. Please hand in a hard copy. I do not need a soft copy of the program.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download