CSC 105 Section:
Name:
Student ID:
Final exam CSC105 – Spring-Summer 1997
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.
Repetitio mater studiorum est[enter]
The fragment is as follows:
while( ( ch = getchar() ) != ‘i’ )
putchar(++ch) ;
Dura lex, sed lex[enter]
The fragment is as follows:
while( ( ch =getchar() ) != ‘\n’ )
{
putchar(ch++);
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:
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.