Professional Documents
Culture Documents
TEST 1
COURSE : COMPUTER PROGRAMMING
DURATION : 1 HOUR
INSTRUCTIONS TO CANDIDATE:
1. This examination paper consists of TWO (2) questions. Answer ALL questions.
2. All answers to a new question should start on a new page.
3. All calculations and assumptions must be clearly stated.
4. Candidates are not allowed to bring any material other than those allowed by the
invigilator into the examination room.
EXAMINATION REQUIREMENTS:
1. None
This examination paper consists of THREE (3) printed pages including the front page
CONFIDENTIAL BMM1312I
Find all errors in the source code given below, and suggest the correction needed in a table.
Source code:
1 #include (stdio.h)
2 int main()
3 {
4 char first; int second; float third;
5 printf ("Hi there. Please enter a character\n");
6 scanf("%s\n",&first);
7
8 printf ("Please enter an integer\n");
9 scanf("%d",&second);
10
11 printf ("Please enter a floating point number\n");
12 scanf("%f",third);
13
14 printf("you have entered %c, %d and %f \n",first,second,third);
15
16 printf("Thank You\n",first);
17
18 return 0;
19 }
20
21
22
2
CONFIDENTIAL BMM1312I
( ) ( )
( )
where x and y are input from the user in radians and M = 0.18. The calculated function
should be in three decimal places and should be displayed on the terminal screen when
the program is executed. (10 Marks)
b) Modify your C program in (a) i.e. use the same mathematical expression, f(x,y) where the
values of M are varied as follow:
if 0 y 0.5
if y > 0.5
Calculate f(x,y) based on the input x and y from the user. The output f(x,y) should be
displayed on the terminal screen in three decimal places as well. (5 Marks)