KIRINYAGA UNIVERSITY
UNIVERSITY EXAMINATION 2024/2025
ORDINARY EXAMINATION FOR BACHELOR OF SCIENCE IN INFORMATION
TECHNOLOGY AND BACHELOR OF SCIENCE IN SOFTWARE ENGINEERING.
SPC 2101 Introduction to Programming & Problem Solving YEAR 1 SEMESTER 1
DATE: TIME:
Instructions: Answer Question 1 and Any Other Two.
Show all your working to earn all the marks
Where possible illustrate with diagrams
QUESTION 1(20 Marks)
a) Differentiate between the following set of programming terms:
i. Algorithm and Program (2 Marks)
ii. Global and local Variable (2 Marks)
iii. High-level language and Machine language (2 Marks)
b) Write pseudocode that describes how to calculate the area of a rectangle (3 Marks)
c) Outline any FOUR C supported data types (4 Marks)
d) Use the For loop to write a C program to print sum of Even numbers from 1 to 10 (3 Marks)
e) Using a C program explain the difference between Function Declaration and Definition. (4
Marks)
QUESTION TWO (20 MARKS)
a) Discuss any THREE programming errors that a C programmer may encounter in the course of
developing programs giving an example in each case (6 Marks)
b) Write a program that prompts the user to enter three numbers and print the least of the given three
numbers. (8 Marks)
c) Discuss the steps in the program development cycle. (6 Marks)
QUESTION THREE (20 MARKS)
a) Describe the term Pointer as used in C programming. (2 Marks)
b) Give the difference between ‘while loop’ and ‘do while loop’ with a syntax example for each
case. (6 Marks)
c) Define a struct called ‘Employee’ that has the following members:
Employee names (string)
Basic salary (floating point)
Gender (string)
Year of birth (integer) (4 Marks)
b) Write a C program that implements the struct defined in (b) above. The program should
create a struct variable that initializes the members with details of one employee and finally
displays those details as output (8 Marks)
QUESTION FOUR (20 MARKS)
(a) Discuss any THREE differences between a compiler and an interpreter (6 Marks)
(b) Write a C Program that calculates the largest of two numbers in a given Array. The program First should
accepts an array, then compares the elements and finds which is the largest two element in a given array.
(8 Marks)
(c) Write a C program that uses a function called calc_vol to
compute the volume of a cube (volume=height*breadth*length). The
main function (main ()) should capture the dimensions of the
cube from a user and finally display the volume returned by
calc_vol function. Note: computations should be done exclusively
by the calc_vol function and not by main (6 Marks)
QUESTION 5 (20 MARKS)
a) Write a c-program that will output the following on the screen: (5 Marks)
NB: the user should enter the number of row
b) Compute the values of the following C expressions assuming that b, s, e, m and k are integer
variables, z and t are float variable as declared below. int b = 1, s = 3, e = 5, m = 4, k = 10;
float z = 2.0, t = 5.5;
i. z=b+k*z/m%e–1 (3 Marks)
ii. e % s * m > z || k % s * b < t (4 Marks)
iii. (b < s) % s+1 (3 Marks)
c) Write a program in C that prompts you to type in your Name, Registration Number and Year
of Study. The program should then display the following output:
Hello STUDENT, your Student Number is REG.NO and you are in your YEAR of study
Where STUDENT, REG.NO, and YEAR are the Name, Registration Number and Year of Study
you provided (5 Marks)