COM 1208-1 programming ope
COM 1208-1 programming ope
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)
(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) 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)
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{
4|Page