Com 121: Procedural Programming I Question Paper

Com 121: Procedural Programming I 

Course:Bachelor Of Science In Computer Science

Institution: Rongo University question papers

Exam Year:2018



UNIVERSITY EXAMINATIONS
RONGO UNIVERSITY
FIRST YEAR EXAMINATIONS SEMESTER 2
FOR THE AWARD OF THE;
DEGREE OF COMPUTER SCIENCE
COM 121; Procedural Programming I
Instructions:
1. Question ONE is compulsory
2. Answer ONE and any other two questions
3. Answer to every question should be started on a fresh page.
QUESTION ONE (30 MARKS)
a) differentiate the following terms: (2 marks @)
(i) Computer program and a programming language
(ii) Syntax and semantics of a programming language
(iii) High level and low level programming language
b) With relevant examples, explain three types of errors that may surface a computer
program (6 marks)
c) Describe the basic structure of a C program. (6 marks)
d) Write a C program that computes and displays the sum of all odd numbers between 1
and 50 inclusive. (6 marks)
e) Given the algorithm below that calculates the average mark of a class of n students,
draw a corresponding flowchart. (6 marks)

Initialize n, sum=0, counter=0 and average=0.
While there are more students
Get the next mark
Add the mark to sum
Increment the counter
Compute average=sum/counter
Display average

QUESTION TWO (20 MARKS)
(a) Define the following terms
(i) Variable
(ii) Expression
(iii) Function
(iv) A bug
(b) Explain the syntax of an if-else statement
(c) Write a program to Find sum, average of any three numbers which are user through the key board.

(d)you are provided with the following code,study it carefully and answer the question

#include
void main(){
.lnt a=5>b=10,c=l;
if(a&8&b>c){
Printf("Barrack Obama");
else{
break;
}
}

*

i) Predict a possible output of the above code when compiled (4 marks)
ii) Explain the reasons for you answer?

QUESTION THREE (20 MARKS)
(a) For each ofthefollowingvariablenames,state which one is valid or invalid, (lmarkeach)
(i) student_number i
(ii) PI
(iii) 2ndTest
(iv) Testl i
(v) mv*name

(b). Magombe writes the following C program to find the sum and quotient of two numbers x and y. Study the program and answer questions that follow
1. Add{
2. int x=10;
3. int y=0
4. int quotient=x/y,
5. int sum=x/y;
6. main() {
7. printf(sum);
8. printf(quotient);
9. }
10. }

10. }


(i). Identify the programming errors in Magombe's program.(3marks)
(ii). In what categories do the programming errors that you have identified i) above fall?
(iii). How can Magombe get rid of the errors?(5marks)

b).
#include
mt addition (int x, int v )
{
int r;
r=x+y;
return (r);
}
int main
{
int z;
z = addition (5.43, 3.21); printf("%d ”,z); return 0;
}
Study the above program carefully and predict a possible output for your answer(4 marks)

QUESTION FOUR(20 MARKS)
As a computer science student,you have been asked to design a program which accepts as input two numbers in the range 0 to 99 inclusive and which sums the numbers, finds the difference of the numbers and displays both th and the difference.
(i) Write pseudo code for the program (5 ma
(ii) Draw a flowchart from your pseudo code in ii) above. (5 mai
(b) Study the code snippet in the C programming language below and answ< questions that follow.
for(intx=0;x< 10;x++){
printf(“%d ” ,x);
}
What is the output of the above code snippet? (3 marks)
Convert the for loop into a while loop (5 marks)
What is the difference between a for loop and a do-while loop?
(2 marks)








More Question Papers


Exams With Marking Schemes

Popular Exams


Mid Term Exams

End Term 1 Exams

End Term 3 Exams

Opener Exams

Full Set Exams



Return to Question Papers