DEDAN KIMATHI UNIVERSITY OF TECHNOLOGY
UNIVERSITY EXAMINATIONS 2014/2015
FIRST YEAR SECOND SEMESTER EXAMINATION FOR THE DEGREE OF BACHELOR OF
SCIENCE IN INFORMATION TECHNOLOGY
BIT 2123 : STRUCTURED PROGRAMMING
DATE: 26TH MAY 2015 TIME: 11.00AM-1.00PM
Answer question 1 and any other two questions
Question one-Compulsory 30 Marks
a) Explain the following terms as used in programming and give an example of each
(12
Marks)
i. Source code
ii. Algorithm
iii. User defined Function
iv. String function
b) Identify any four categories of operators used in C programming. In each category, give
an example (4 Marks)
c) Identify three symbols and specify their role as used in program design (6 Marks)
d) Using code segment, show how the following can be accomplished in C programming
i. Declaring two integer arrays of equal size e.g. 100 (2 Marks)
ii. Initializing the first five elements of both arrays(through the keyboard)(2 Marks)
iii. Using a for loop, finding the product of two arrays-assume the arrays have n
elements and the results are put in array called num (2 Marks)
iv. Overwriting the content of one of the arrays you multiplied together (in above)
with contents of array num(product) (2 Marks)
Page 1 of 4
Question Two-20 Marks
a) Explain any two types of errors that may be encountered in a computer program and give
an example (4 Marks)
b) Using a program segment show how a function is called and arguments passed by another
(4
Marks)
c) Identify and briefly explain the effect of any four errors in the program below(4 Marks)
#include<stdio.h>
void main()
{
int j,num_1;
for(i=1;i< num_1,i++);
printf(“%d\t”,i);
}
d) Write a C code segment using a for loop that calculates and prints the product of the odd
integers from 1 to 15, both limits inclusive (8 Marks)
Question Three-20 Marks
a) Identify and describe the use of any three data format specifiers (6 Marks)
b) Explain the role of line 1,4 and 6 of the code segment below then present the output
formatted as designed in the program (6 Marks)
1 int i=10,sum=0;//declaration statement for variables-to reserve
memory
2 while(i<30)
3 {
4 if ( i%4==0 || i%6==2) // determine if a value is evenly
divisible by 4 or if the value is divided by six 2
remains
5 {
6 sum+=i; // Does summation sum=sum+i
Page 2 of 4
7 printf("%d\t ", i) ;
8 }
9 i++;
10 }
11 printf("\n");
12 printf("Sum of the values is %d\n", sum);
Output
c) Design a program in C with a function that receives from main both weight in KG and
height in feet of a human being then converts the height into metres (1ft is 30 cm) and
computes BMI.
BMI=weight(kg)/Height Squared (Metres).The result is displayed in main function
(8 Marks)
Feet multiplied by 30 divided by 100 gives height in metres
Receive both weight and height
Pass both weight and height to function
Convert height into metres
Compute BMI using formula given
Return BMI
Question Four-20 Marks
a) Explain why C is case sensitive (2 Marks)
b) Identify any three keywords in C and explain how they are used (3 Marks)
c) Study the code segment below, explain every statement and state the value of str2 and
num1 after execution
(4 Marks)
char str1[] = {“Book”}; declares and initializes array of characters called str1
Page 3 of 4
char str2[20] = {“Chains”}; declares and initializes array of characters called str2
of size 20
strcat(str2,str1); concatenates string str2 and str1. The result is str2
num1=len(str2); determines length/number of characters in str2(after
concatenation)
d) Show two ways using code segment how constants can be used in an expression
(4 Marks)
e) Declare an array that receives five values using for loop and prints then in reverse order
(3 Marks)
Question Five-20 Marks
a) Differentiate between the following declarations (4 Marks)
i. char ch and char ch[10]
ii. int num[5] and int num[4][3]
b) Show how you can declare and initialize two dimension array with all elements equal to 1
(4
Marks)
c) Design a program that can receive two matrices of dimension 2 by 2, sum
them ,determine their product and provide the results (12
Marks)
Page 4 of 4