Cosc 101 111
Cosc 101 111
-----------------------
a).#include b).#define 17. Identify and correct the error(s) in each of the following:
int x = 1, total;
6. T/F. Comments are executable by the compiler. False while ( x <= 10 ) {
total += x;
7. What happens if a compiler encounters the following
++x;
statement: // printf(“\n This is solvable”);
}
11.What is the output of the following code if number of lines Expected Output :
input is 5?
Input hours: 5
#include <stdio.h>
Input minutes: 37
int main() {
Total: 337 minutes
int n, i;
printf("Input number of lines: ");
scanf("%d", &n);
20.Define an array called “Numb” to store the first 10 natural
for(i = 1; i <= n; i++) {
numbers. Do the following:
printf("%d %d %d\n", i, i*i, i*i*i);
i).Write two statements to display the first and the last elements
}
ii).Suppose sum = Numb[0]+Numb[3]. What is sum+=Numb[5]?
return 0;
}
12. Use while loop to re-write this code:
Q
Section B (Answer any Three (3) Questions
1(a). There are four ZONES- West, East, North and South. Write a C program to read the age and the state of a
candidate, then determine whether he is eligible to vote. If eligible then display “Good To Vote-Congratulations”
otherwise display “My Friend TOO YOUNG TO VOTE Sorry!!. You can vote only after 18 years of AGE”.
Rules: If you are above 18 and from the WEST, EAST and SOUTH then you are eligible to vote otherwise not
eligible, if you are from the NORTH and of age less than 18 but greater than 14 then you can vote.
8mks
(b)(i) Write a C program that accepts principal (P), rate of interest(R), time(T) and compute the simple interest.
PRT
Given that ∫amt ¿ 100 . 6mks
(ii) Write a program in C to store elements in an array and print them out. 6mks
2(a).List in an ordered form the steps to be followed during development of a computer program to solve a problem.
. 5mks
2(b)(i). Consider the following code and debug for successful compilation: 5mks
//Program …
#include <stdio.h>
int main()
{
int n;
printf(“Value\n”);
scanf("%d", &n);
if(n%2==0);{
printf("\t The result : %d", n);
}
else{ printf("\t The result is not: %d", n); }
}
}
2(b)(ii) Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several
tank-full of fuel by recording kilometers driven and liter used for each tank-full. Develop a C program that allows
user to input the kilometer driven and liter used for each tank-full. The program should calculate and display the
kilometer per liter obtained for each tank-full. After processing all input information, the program should calculate
and print the combined miles per gallon obtained for all tank-full. To terminate processing you can enter -1 for
number of liters used. 10mks
3(a). Write a C program that reads an integer between 1 and 12 and print the month of the year in English 8mks
b).For a new student in Babcock University to be fully registered and allocated a room in a hall the student must
fulfill the following dependent conditions. 4mks
--must have letter of admission
--must have paid school fees and get financial approval.
--complete online registration and have course form
--lastly must have an ID card
i).With the use of nested-if develop an algorithm to simulate this process.
ii).Study the following program and answer the following questions:
#include <stdio.h>
/* height and width of a rectangle in inches */
int width;
int height,
int area; perimeter;
int main() {
height = 7;
width = 5;
perimeter = 2x(height + width);
printf("Perimeter of the rectangle = %d inches\n", perimeter);
area = height x width
printf("Area of the rectangle = %d square inches\n", area);
return(0);
b) Write a C program that accepts an employee's ID, total worked hours of a month and the amount he received per
hour. Print the employee's ID and salary (with two decimal places) of a particular month. 5mks
=================================