Exam22 Past Paper
Exam22 Past Paper
Instructions:
Part I
main()
{
int a = 5;
a++;
printf("%d", ++a);
}
a) 5 b) 6 c) 7 d) 4
Part II
Write the general structure (syntax), give an example and explain the given
example of the following C concepts
4 marks each
a) if else statement
b) switch statement
c) do while loop
d) structure definition
e) conditional statement
Section B (Choose any three questions)
Question one
a) Write a program that finds the largest and the smallest number of the
two numbers input by the user.
8 marks
i) break
3 marks
ii) continue
3 marks
54321
54321
Question Two
d) Write a program that requests for three integers from the user and
displays the sum.
8 marks
Question Three
b) Write a program that finds and displays prime numbers in the range of
1 to 20 and also displays how many they are at the end of the
program. 8 marks
c) Write a program that requests marks from a user and keeps asking the
user to enter a valid mark as long as the mark entered is greater than
100 or less than 0. The program should print ‘’Retake” if the mark is
below 50, print “excellent ” if the mark is 75 to 100 and print ”
Passed” if the mark is 50 to 74 . The program should accept marks for
up to 100 students but the user can type -99 to end the loop if the
students in the class are below 100 and all the marks have been
entered.
Hint: the marks should be kept in an array
10 marks
Question Four
a) Write a program that reads and display all names stored in a file
named NAMES.txt
6 marks