0% found this document useful (0 votes)
4 views

Sample Past paper

The document is a sample past paper consisting of five questions related to C programming, algorithms, and data types. Each question includes multiple parts, such as differentiating terms, writing programs, designing flowcharts, and explaining concepts. The paper assesses knowledge on syntax errors, control structures, function prototypes, and various programming constructs.

Uploaded by

samwel.ochieng21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Sample Past paper

The document is a sample past paper consisting of five questions related to C programming, algorithms, and data types. Each question includes multiple parts, such as differentiating terms, writing programs, designing flowcharts, and explaining concepts. The paper assesses knowledge on syntax errors, control structures, function prototypes, and various programming constructs.

Uploaded by

samwel.ochieng21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Sample Past paper

Question One-Compulsory-30 Marks


a) Differentiate the following terms (10 Marks)
i) Syntax errors and logical errors
ii) Source code and Object code
iii) Selection and Iteration control structure
iv) Actual parameters and Formal parameters
v) Global variables and Local variables
b) Write a C program that stores marks of five students in an array, computes their sum and average. The program
should display the computed sum and average. (6 Marks)
c) A student can be graded using the following system. Write a flowchart for the above grading system.
(5
Marks)
Score Grade
greater than or equal to 70 A
greater than or equal to 60 B
greater than or equal to 50 C
greater than or equal to 40 D
Less than 40 F

d) Using examples, explain the differences between a pre-test and post-test loops (6 marks)
e) Functions in C programs communicate information using parameters. During function declaration, a function
prototype is created. Show how a function prototype is declared (3 Marks)

Question Two-20 Marks


a) Define computer algorithm and list any four characteristics of an algorithm (6 Marks)
b) Explain briefly the two reasons why variables must be declared before use. (4
Marks)
c) Write a program that asks the user to enter two numbers and computes the sum and difference according to the
following rules. The sum is computed when the first number is less than the second number. The difference is
computed when the first number is greater than the second. Define two functions add () and difference () to
perform the operations. Output the results by calling the relevant functions (10 marks)

Question Three-20 Marks


a) Describe the following data types and give the key word used to declare them in C Programming
(6
Marks)
i. Integer
ii. Floating point
iii. valueless
b) State the role of the following escape sequences using an example (4 Marks)
i. \n
ii. \t
iii. \v
iv. \a
c) Given that c=5/9*(f-32) where c=degree in Celsius and f=degree in Fahrenheit, make f the subject of the
formula and design a program that request the user to specify the units for input value then converts to the
other units. E.g. if a user loads the program and specifies that the units in use are Celsius then inputs 100, the
program outputs “100 degrees Celsius is equal to 212 degrees Fahrenheit” (10 Marks)

Question Four-20 Marks


a) Explain why the following code segment will not terminate and introduce the statement that will make the loop
terminate (4 Marks)
do
{
n=10;
Printf(“%d”,n);
n++;
}
while(n<20)
b) Design a code segment using for loop that can generate a multiplication table of n numbers as shown below
(6
Marks)
1 2 3 4 . n
2 4 6 8 . n*2
3 6 9 12 . 2*3
.
n n*2 n*3 n*4 . n*n

c) Write a program that accepts three integer numbers, determines the largest and the smallest of the numbers
then divides the largest by the smallest number displays: Largest, Smallest and the result of the division. The
program should display appropriate message when the smallest number is Zero (8 Marks)

Question Five-20 Marks


a) Describe the following terms (8 Marks)
i. Array
ii. Function
iii. Structure
iv. Pointer
d) Write a C program that stores marks of n students in an array, computes their sum and average. The program
should display the computed sum and average. n is an integer user input (8 Marks)
b) Show how you can declare and initialize an array of structure. The structure name is stud_details and contains
elements name(array of characters, age(integer) and Mstatus(Character) (4 Marks)

You might also like