20 marks.
25 marks.
25 marks.
20 marks.
Page 1 of 5
1(b) The following segment of code reads in numbers from the console, computes the
running maximum and prints to the screen. For example, if the use enters 3 8 6 10, one
value on each line, the program should output 3 8 8 10. The code contains at least three
(3) logical errors that will not result in the intended operation of the code. Identify each
of the errors and specify the solution. [3 marks each, 9 marks in total]
#include <stdio.h>
#define FALSE 0
#define TRUE !FALSE
void main( void )
{
int maximum;
int value;
int firstNumber = TRUE;
printf( "input numbers to compute the maximum as each is
entered\n" );
printf( "end by inputting ^C\n" );
do {
printf( "input next number: " );
scanf( "%d", value );
if ( firstNumber == FALSE )
{
maximum = value;
firstNumber = FALSE;
}
else if ( value > maximum )
maximum = value;
printf( "current maximum: %d\n", maximum );
} while ( 1 );
}
Page 2 of 5
float %fred;
double float;
int answer;
int x_coord;
(f)
(g)
(h)
(i)
long int z;
char country of origin[100];
char hair_colour[10];
int *y;
Page 3 of 5
Page 4 of 5
END OF EXAMINATION
Page 5 of 5