Escolar Documentos
Profissional Documentos
Cultura Documentos
UNIVERSITY EXAMINATIONS
MAIN CAMPUS
INSTRUCTIONS
1. Section A is compulsory, and then Attempt any other two questions from section B:
2. Do not write anything on this question paper.
programming: (4 marks)
As members of Kabarak University family, we purpose at all times and in all places, to set apart in one’s
heart Jesus as Lord. (1 Peter 3:15)
i. while loop
ii) do – while loop
c. Show the output of the following two codes given in (i) and (ii) below. (4 marks)
i) include<stdio.h>
main ( )
{
int i = 0 ;
while (i > 2)
{
printf(“%d”, i);
i++;
}
return 0; }
ii) #include<stdio.h>
main( )
{
int i = 1 ;
do
{
printf(“value of i is %d”, i);
i++;
}
return 0;
}
As members of Kabarak University family, we purpose at all times and in all places, to set apart in one’s
heart Jesus as Lord. (1 Peter 3:15)
printf (“\n\t %s \n\t %s \n”, LINE, TITLE);
printf(“\t %s \n”, LINE);
return 0;
}
f. i) Using C language, write a program that would test and display if an integer entered by
the user is ODD or EVEN (4 marks)
ii) As in e(i) above, use a conditional operator to write a programthat would do the
SECTION B
main( )
int x = 10, y = 20 ;
if ( x == y )
As members of Kabarak University family, we purpose at all times and in all places, to set apart in one’s
heart Jesus as Lord. (1 Peter 3:15)
QUESTION THREE(20 marks)
a. Write a program to calculate the sum of 10 numbers entered from the keyboard. Negative
numbers will not be included in the calculation. (Use a for-loop) (8 marks)
case constant2:
// code to be executed if n is equal to constant2;
break;
.
.
.
default:
// code to be executed if n doesn't match any constant
}
c. Write a program just to print/display an integer entered by a user, and show the output
(4 marks)
As members of Kabarak University family, we purpose at all times and in all places, to set apart in one’s
heart Jesus as Lord. (1 Peter 3:15)
printf("string_a is %s\n", string_a);
printf("string_b is %s", string_b);
}
b. Using conditional operator, write a programto find the biggest number between two
integer numbers entered by the user. (4 marks)
c. Based on file concepts, explain the differences between the following two terms:
(2 marks)
i) fclose(a) (ii) fcloseall()
d. Using User defined function, write a program to add two integer numbers entered by the
user. The main() function should pass those two numbers to a function called
addNumbers() that is going to add the two numbers together and return the result to the
main() function to display on the screen (6 marks)
e. Explain the concepts of the following C code and show the output (4 marks)
#include<stdio.h>
int A;
int B;
int Add()
{ return A + B;
}
int main()
{ int answer;
A = 5;
B = 7;
answer = Add();
printf("%d\n",answer);
return 0;
}
As members of Kabarak University family, we purpose at all times and in all places, to set apart in one’s
heart Jesus as Lord. (1 Peter 3:15)
f. What would be the output of the following c code? (2 marks)
#include <stdio.h>
int main () {
b. Using a pointer, write a program in C that would print out the values of two declared
integer variables along with their addresses (6 marks)
c. Write a program using C language that would be used to show the net pay of an
employee based on the following information: Nhif = ks. 200.50 andTax is 30% of
the gross pay. Restrict the net pay to two places of decimal. (5 marks)
As members of Kabarak University family, we purpose at all times and in all places, to set apart in one’s
heart Jesus as Lord. (1 Peter 3:15)