Com 121
Com 121
Question 2:
(a) Explain the following terms in C programming with examples:
(i) Token (ii) Comments (iii) Semicolon (iv) Header files
(b) Identify the tokens available in the statement below and their respective function.
printf("Programming is fun \n");
Question 3:
(a) With adequate example, explain the following C programming terms:
(i) keyword (ii) Expression (iii) Statement (iv)Symbolic Constants
(b) Debug and rewrite the correct version of the C program given below in your answer booklet:
#include
main()
int distance=33
float time=10.7
char school;
double speed;
speed=distance*time;
printf("value of time taken is %f\n", );
printf("value of distance taken is %d\n",distance);
printf("value of speed of car is %.4f\n",speed);
}
Question 4:
(a) Give the syntax for the following decision making statements in C programming
(i) if statement (ii) if...else statement (iii)switch statement
(b) Demonstrate the use of switch statement with a valid example.
Question 5:
(a) Outline the four (4) categories of operators in C-Programming and list out their respective
operators.
(b) Write complete C program to show the use of Relational and Logical Operators.
Question 6:
(a) Write a C program to calculate the percentage of a user's score in relation to the
maximum score in a game if the maximum score is 500 and the user’s score is 420.
(b) Give the output for the c program below:
#include <stdio.h>
main()
{
int a = 20;
int b = 10;
int c = 15;
int d = 5;
int e;
e = (a + b) * c / d;
printf("Value of (a + b) * c / d is : %d\n", e );
e = ((a + b) * c) / d;
printf("Value of ((a + b) * c) / d is : %d\n" , e );
e = (a + b) * (c / d);
printf("Value of (a + b) * (c / d) is : %d\n", e );
e = a + (b * c) / d;
printf("Value of a + (b * c) / d is : %d\n" , e );
return 0;
}
Question 7:
(a) Assuming a student’s grade is A in a given course. Use a switch statement to write a
program that prints the student’s grade.
(b) With a valid code snippet, show the difference between the “gets function” and “puts
function”