CIT 3102 Programming Supp Town
CIT 3102 Programming Supp Town
c) State the role of comments in programming and discuss the two ways in which comments are
represented in a C program. (5 Marks)
d) A solution is required that requests the user for the overtime hours worked by an employee and
the advance pay taken by an employee during the month the solution then determines the pay of
the employee based on the following guidelines: basic pay ksh 47,500 per month, overtime
allowance of ksh 1,000 per hour. Required:
i. Devise an algorithm to solve the problem (5 Marks)
ii. Write a C program to solve the problem (5 Marks)
e) Define the term variable and discuss any THREE rules guiding the naming of variables.
(4 Marks)
Question TWO (20 marks)
a) Using a SELECT CASE statement write a program in C that allows a user to key in a number between 1
and 8; the program then outputs the number in words.
(6 Marks)
b) Identify and correct the errors in the following program. After corrections, what output would it
produce when executed? (5 Marks)
#include<stdio.h>
void main()
{ Float pi = 3.142;
float radius, c, a;
r = 7;
c = pi * 2 * r;
a = pi * r * r;
printf("The area is %f", a);
printf("\nThe circumference is %f", c)
c) Discuss the role of functions in a C program and write the syntax for defining a function.
(4 Marks)
d) Write a C program to input two numbers then use a user defined function to calculate the sum of
the two numbers entered and display the result. (5 marks)
Question THREE (20 marks)
a) Discuss any THREE differences between a compiler and an interpreter. (6 Marks)
b) Discuss the role of variable declaration in programming and write an example statement that
declares a variable. (4 Marks)
c) Write the syntax and discuss the parts that make up the for loop. (5 Marks)
d) Write a C program that accepts a user input number and computes and displays the square and
the cube of the number. (5 Marks)
Question FOUR (20 marks)
a) Discuss the steps followed by a programmer as he/she develops a solution to a problem.(6 Mks)
c) Design a flow chart for a solution that calculates the average of a set of N(user specified)
numbers. (5 Marks)
d) Write the output of the following sections of code [4 Marks]
Int x[5]={5,2,7,5,8}
C,count=0;
For (c=0; c<5; c++)
If (x[c]>5)
Count++;
Printf (“%d”,count);
e) Design a C program to input employee name, hours worked and rate per hour then calculate the
basic pay =hours worked * rate per hour, tax is charged according to basic pay. If basic pay is
greater than 20000, a tax of 10% of basic pay is charged, otherwise a tax of 5% is charged. Net
salary = basic – tax. The program should display employee name, basic salary, tax and net salary.
(5 marks)
Question FIVE (20 marks)
a) Write a program in C that accepts a user input number and checks if the number is even or odd;
the program then outputs the appropriate message. The program should allow the user to repeat
the process five times. (5 Marks)
b) Write a program using C to print the triangle of asterisks shown below [5 Marks]
*
**
***
****
*****
c) Write a program in C that accepts ten user input cat marks, stores them in an array and calculates
and display the average cat mark. (6 Marks)
d) State the name, discuss the role and cite an example usage of the operator: % in programming.
(4 Marks)