DEDAN KIMATHI UNIVERSITY OF TECHNOLOGY
University Examinations 2018/2019
BACHELOR OF SCIENCE IN BED MECHANICAL ENGINEERING, BACHELOR OF
SCIENCE IN BED ENGINEERING, BACHELOR OF SCIENCE IN ELECTRICAL AND
ELECTRONIC ENGINEERING, BACHELOR OF SCIENCE IN MECHATRONICS
ENGINEERING, BACHELOR OF SCIENCE IN CHEMICAL ENGINEERING
SMA 2175: COMPUTER PROGRAMMING 1
DATE: 16TH April 2019 TIME: 11:00AM-1:00PM
Instructions: Answer Question 1 and Any Other Two.
Question 1: (30 Marks)
a) Describe how programming languages are classified. Give examples to each. [4 Marks]
b) Define the following terms:
i. Programming. [1 Mark]
ii. Flowchart. [1 Mark]
iii. Debugging. [1 Mark]
c) Differentiate between a structure and union, in each provide the syntax. [4 marks]
d) Using an example, outline the syntax for initializing the elements of a one dimensional array
dynamically. [3 Marks]
e) Write a c program that performs four basic arithmetic operations. [5 Marks]
f) What is the first and the final values of i output by this loop. [2 Marks]
n=10;i=0;
do {
printf(“%d”,i);
}
while (++i<n)
g) Differentiate between the following terms
i. Function and Function prototype [2 Marks]
ii. While and do-while statements [2 Marks]
h) Write a declaration of a structure called account with account_number, first_name ,
last_name and balance as its fields. [2 Marks]
1
i) The following program is supposed to find the square and cube of 5, but it has errors.
Rewrite the correct code [3 Marks]
#include<stdio.h>
void main()
{
int, x2, x3;
printf(“xsquare=%d ,xcubed=%d\n”, x, x2, x3);
}
Question Two: (15 Marks)
a) Describe three drawbacks of Assembly Language. [3 Marks]
b) Differentiate between the following:
i. Loader and Linker. [2 Marks]
ii. Assembler and Compiler. [2 Marks]
c) Write a program to swap two integer numbers using pointers. The swapping operation
should be implemented using a function. The output should give the values before and
after the swap [5 Marks]
d) Write and explain the output of the following C program. [3 Marks]
#include<stdio.h>
main()
{
int a=2, b=12;
printf(“a=%d\n, a--);
printf(“b=%d\n, --b);
}
Question Three: (15 Marks)
a) Write a C program to compute the total marks scored by a student who sat for 4
subjects in an exam. Include the code for awarding grades where (70%= First
Class, 60% =Second Class, 50%=Pass, and below 50% =Fail) [6 Marks]
b) Suppose a, b, c are integer variables assigned the values a = 8, b and c = - 5. x, y, z are
floating point variables with values x = 8.8, y = 3.5, z = - 0.5. Determine the value of
each of the following expressions [6 Marks]
i. x / y + z * y
ii. 2 * b + 3 * (a – c)
iii. (a * c) % b
2
c) Explain any three advantages of C Programming language. [3 Marks]
Question Four: (15 Marks)
a) Identify and explain three categories of control statements. [3 Marks]
b) Discuss the unary operator using an example. [2 Marks]
c) Using a while loop write a program to compute the sum of the first n natural numbers.
[5 Marks]
d) Write a program in C that takes minutes as input, and display the total number of hours
and minutes. [5 Marks]