CIT-3102-FUNDAMENTALS-OF-COMPUTER-PROGRAMMING-1
CIT-3102-FUNDAMENTALS-OF-COMPUTER-PROGRAMMING-1
a) Using a SWITCH statement, write a C program that prompts a user to enter two integers.
The program then prompts a user to select from options 1-3 inclusively. If a user selects
option 1 the code returns the sum of the two integers, if the user selects option 2 it returns
the product of the numbers; if the user selects option 3 it returns the sum of the squares of
the numbers (5 Marks)
b) Write a C program, using a WHILE LOOP, to print the sum of all odd integer numbers
between 1 and 20. (5 Marks)
c) Describe the various stages of a software development life cycle (5 Marks)
d) Write a function to calculate and return the factorial of a number supplied to the function
as a parameter. (5 Marks)
a) Design a flow chart for a solution to a problem of calculating the average of a set of n (user
specified) numbers. (6 Marks)
b) Write a C program to accept two integers, determines and display the largest among them
on the screen. (5 Marks)
c) Outline the five rules that should be followed when declaring variables in C.
(5 Marks)
d) Using an example, explain the following terms as used in C programming. (4 Marks)
i) Type casting
ii) Dry running
c) Study the program code below, then identify the errors, and rewrite the correct program
code without the errors. (5 Marks)
#include <stdio.>
void main()
{
int a, b, sum, product
double 8average;
printf("Enter a value for a\n”);
scanf(“%d”,a);
printf("Enter a value for b\n);
scanf(“%d”,&c);
sum = a + b;
product=a*b;
8average = (double) sum/2;
printf(“\n%d+%d=%d”,num1,num2,sum);
printf("The average is %4.2lf\n”);
return 0;
)
b) Write a C program that output values that are divisible by 3 in descending order, between 1
and 100 (5 Marks)
c) Watoto CBC class has 15 pupils, who learn 3 subjects (Maths, English, and Drawing)
each. Using arrays, write a code that will enable their teacher capture the marks of all the
students and display the marks and totals for each student. (each student marks should be
in its own line, separated by a tab space placed under the subject title). (6 Marks)
d) Use examples to describe two ways of representing comments in C programming.
(4 Marks)