C Programming Test
C Programming Test
c programming test
NAME :
MATRIX NO :
PROGRAM : VENUE:
LECTURER :
Instructions:
1. This is a close book test. No books and notes are allowed to be referred to during the test.
2. There are TWO (2) parts of questions. Answer ALL questions. Please write your answer
in the column provided.
3. Time given: 1.5 Hours.
4. Number of pages (including this page) : 6
1. Based on the LinuX environment programming, compile the "name.c" program to result the
output to a file name "name.out". State three (3) methods of command that can be use for
both compiling and execution/running the “.c” file and “.out” file. [6 marks]
c. 𝑎 ≠ 𝑏 a!=b [1Mark]
d. 𝑧 ≤ 𝑥 z<=x [1Mark]
e. 𝑚 ≥ 𝑛 m>=n [1Mark]
5 2 . 3 1 3 4 0 0
5 2 . 3 1 3 4 0 0
5 2 . 3 1
5 2 . 3 1 3
Initialize flag = 0
true
iSpeed >50? Set flag = 1
false
Decrease iIndex by 5
Increase iSpeed by 1
false
Figure 1
[Answer]
flag = 0; [1M]
do [1.5M]
{
if(fSpeed >50) [1.5M]
flag=1; [1M]
else [1.5M]
{
iIndex -=5; [1M]
iSpeed++; [1M]
}
}while(flag != 1); [1.5M]
1. Write a program that will display a conversion table of temperature in Celsius to Fahrenheit.
The program requires the user to enter initial Celsius temperature, Celsius temperature limit
and the increment of Celsius value. The formula for conversion:
Fahrenheit=1.8×Celsius+32.0. Please use for.. statement.
Sample output:
Table of Celsius to Fahrenheit Conversion
Please enter the initial Celsius value:
5
Please enter the limit Celsius value:
25
Please enter the increment Celsius value:
5
Celsius Fahrenheit
5 41.00
10 50.00
15 59.00
20 68.00
25 77.00
a) Draw the flowchart for the program.[8Marks]
Start [0.5Mark]
Read initial,limit,increment
value in Celsius [1Mark]
C=begin [1Mark]
End [0.5Mark]
#include<stdio.h> [0.5mark]
int main ()
{
int C,begin,limit,step; [1.5mark]
float F; [0.5mark]
for(C=begin;C<=limit;C+=step) [1.5mark]
{
F=1.8*C+32.0; [1mark]
printf("%3d%12.2f\n",C,F); [2mark]
}
return 0; [0.5mark]
} [0.5mark]