Professional Documents
Culture Documents
UNIVERSITY EXAMINATIONS
2015 / 2016 ACADEMIC YEAR
FOR THE DEGREE OF BACHELOR OF COMPUTER SCIENCE
COMP 120: STRUCTURED PROGRAMMING
SECTION A:
QUESTION ONE [30 marks]
a. Identify any four keywords used in C language (4 marks)
c. ii) Look at the code below and show how you would display the output with only two
places of decimal? (2 marks)
int main ( )
{ float a = 10.250000;
printf(“the value of a is %f”, a);
}
Page 1 of 5
d . Explain each of the following data types as used in C programming language: (2 marks)
e. Explain the differences between a variable and a constant as used in C language (2 marks)
f. Explain the differences between Formal parameters and Actual parameters (4 marks)
g. Identify the differences between the following two terms in relation to functions: (2 marks)
h. Write a program that would determine if a character entered is a vowel or not by entering
any one character and showing some output (6 marks)
j. The following program has some errors, make the corrections and show the output. (4 marks)
SECTION B:
QUESTION TWO (20 marks)
a) i) Outline six benefits of pointers as used in C language (3 marks)
ii) Show how you would declare and initialize a pointer in C- language (3 marks)
b. i) Show how you would declare and initialize an integer array of four elements. (2 marks)
Page 2 of 5
ii) Write a C code to display the output of the above mentioned elements in b(ii) (4 marks)
iii) What would happen if the size of an array is omitted during declaration? (2 marks)
a. Sketch a simple code to show how each of the following operators are used in C
language: (6 marks)
i) Arithmetic operators
ii) Assignment operators
iii) Relational operators
b. Study the following two codes written in C and answer the questions that follow:
i) int main()
{
int a = 0;
while(a < 3)
{
printf("loop iteration is %d\n", a);
if(a == 2) break;
a++;
printf(" go to the next round\n");
}
return 0;
}
ii) int main()
{
int a = 0;
while(a < 6)
{
a++;
Page 3 of 5
if(a == 4) continue;
printf("loop iteration is %d\n", a);
a. Identify and explain three types of decision making in relation to if control statements in C
language. (6 marks)
b. Explain the nature of the following code, and state the output. (6 marks)
#include <stdio.h>
void count(int x);
int main()
{
int num;
Page 4 of 5
printf("Enter a positive integer:");
scanf("%d",&num);
count(num);
}
void count(int x)
{
printf("%d\n", x);
--x;
if(x < 0)
return;
else
count(x);
}
c. Write a C code to show how to find the memory size of a given integer variable (6 marks)
d. Explain the importance of using comments in C programming (2 marks)
a. Write a program in C whereby the main() function would call another function to print/display
exactly the
Hi!
My name is Tom
How are you?
b. Construct a C code to show how to swap two integer numbers entered from the keyboard
(6 marks)
c. Using a conditional operator, write a program in C to find if a number entered from the
Page 5 of 5