CSC 105 Section:


Student ID:


Final exam CSC105 Spring-Summer 1997



  1. Find the value of quack after each line:

int quack = 6 ;

quack -= 5 ; 1

quack += 6 ; 7

quack *= 10 ; 70

quack /=2 ; 35

quack %= 3 ; 2


2. What is the output of each of the following fragments for the indicated input (assume that ch is type int and that the input is buffered)? Explain.


  1. The input is as follows:

Repetitio mater studiorum est[enter]


The fragment is as follows:

while( ( ch = getchar() ) != i )

putchar(++ch) ;



  1. The input is as follows:

Dura lex, sed lex[enter]


The fragment is as follows:

while( ( ch =getchar() ) != \n )



putchar(ch--) ;



3) Write a function that calculates the difference of two integer values. The function will take two integer values a and b and return another integer value which is the difference a-b.

4) Write a C program which will:

  1. Define two arrays of 20 integer numbers
  2. Read 20 number from the standard input into the first array
  3. Use the function defined above to calculate the difference of each two adjacent elements from the first array and store it in the correspondent element of the second array
  4. Print the content of both arrays

Example: If the content of the first array was 1,2,3,4,2, the content of the second array should be 1-2=-1, 2-3=-1, 3-4=-1, 4-2=2. The program should print 1,2,3,4,2 and 1,-1,-1,2. Note that the second array has one element less than the first one.


5) Extra credit Write a function that calculates the sum of its arguments. The function will take 4 double arguments and will return a double value. Write a small program which uses the function.