EXAMINATIONS FOR 2022/2023 ACADEMIC YEAR
EXAMINATIONS FOR B SC. IN COMPUTER SCIENCE
COURSE CODE: COM 1208-1
COURSE TITLE: PROCEDURAL PROGRAMMING
DATE: 25th APRIL, 2023 TIME: 2:30 P.M-4:30pm
INSTRUCTIONS
Answer Question ONE and any other TWO Questions From Section II
Question 1 is compulsory.
Time 2HRS.
SWITCH OFF your mobile phone.
1|Page
Section I, Compulsory (20 marks)
(a) Discuss the difference between machine language and an algorithm
(4 marks)
(b) As a good programmer, discuss three steps you would follow to
write a program . (3 marks)
(c) The factorial of a number X is given by X*X-1*X-2*X-3.....................*1.
The factorial of 0 and factorial of 1 are both 0. Write an algorithm for
computing the factorial of a number between 0 and 10. (4 marks)
(d) Explain any two methods you would use to insert comments in
your C program (2 marks)
(e) Give any three basic data types (3 marks)
(f) Declare an array variable that can accommodate a maximum of
thirty data elements. (2 marks)
(g)Explain each of the following C functions. Where would you apply
them when using C programming? (2 marks)
i. strset
ii. strrev
2|Page
Section II, Answer any two Questions Maximum (30 marks)
Question 2 (15 marks)
(a) Describe the general structure of a C program (5 marks)
(b)By declaring any three appropriate variables, write a program to compute
the sum of two integers. Your program should prompt a user to enter any
two integers, compute the sum and output the results (10marks)
Question 3, (15 marks)
(a) Declare an array large enough to take 0-79 characters. Use it in a simple
C program that would prompt a user to type his name in small letters
and reproduce the name in capital letters (5 marks)
(b) Using strcpy, write a simple C program that reproduce/display the words
"Welcome to Maasai Mara university
where programmers are made"
(5 marks)
(c) Using C programming Language, perform the following;
i. Define an array of size 5 (2 marks)
ii. Assign any five elements to the array (3 marks)
3|Page
Question 4, (15 marks)
(a) Write a program to compute the surface area and volume of a cylinder.
Your code should prompt the use to enter the radius of a cylinder, and
then prompt the user to enter the height of a cylinder after which your
code calculates and outputs the surface area and volume of the
cylinder. HINT: mathematically, the volume of a cylinder is calculated by
the formula; V=πr2h while surface area is A=2 πrh +2 πr2 (5 marks)
(b) Using the switch statement, rewrite the following code (10marks)
#include<stdio.h>
main(){
int a;
if(a>=0){
printf("a is greater than zero\n");
if(a>5){
printf("a>5\n");
if(a>10){
printf("a>10");
}
}
else{
printf("a is less than zero");
4|Page