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

SPC 2107 introduction to computer programming year I semester

Uploaded by

kiprop.24020
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

SPC 2107 introduction to computer programming year I semester

Uploaded by

kiprop.24020
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

UNIVERSITY EXAMINATION 2021/2022

YEAR I SEMESTER EXAMINATION FOR THE DEGREE OF BACHELOR


OF EDUCATION (SCIENCE)
SPC 2107: introduction to computer programming year I semester

Date: Tuesday, 1st February 2022 Time: 11.00am – 1.00pm


INSTRUCTIONS

i. This EXAMINATION has TWO sections.


ii. SECTION A is compulsory. Answer ALL questions in this section.
iii. Answer ANY TWO questions in SECTION B.

QUESTION ONE: (30 MARKS) COMPULSORY

a) Define the following words as used in C programming language giving relevant


examples in each. (4 marks)
i. Keyword
ii. Identifier

b) C operators are symbols that are used to perform mathematical or logical


manipulations. Explain the following operators as used in C language giving
examples (6marks)
i) Relational operators
ii) Arithmetic operators
iii) Logical operators
c) The following is a C program to compare numbers entered by a user. Identify and re-
write the code without errors (6 marks)

Page 1 of 4
#include stdio.h
main
int number;
printf (“enter an integer number”)
scanf(“%”,&number
if(number<100
printf “your number is smaller than 100”
else
printf(“your number contains more than two digits”)

d) Describe the use of the following escape characters and format specifiers used in C
language (4 marks)
i) \n
ii) !=
iii) \t
iv) %d
e) Write a C program that reads the radius of a sphere and calculate the volume.
Where volume =4/3 r3. (6 marks)
f) In C language identifiers are the names given to variables, constants, functions, and
user-defined data. Give four rules applied when naming an identifier.
(4 marks)

QUESTION TWO: (20 MARKS)

a) C has various standard data types that are used to define the operations possible on
them and the storage method for each of them. Explain five data types used in C
language. (10 marks)
b) Kirinyaga University has hired you to write a program that will help implement a
grading system for students. The examination department has provided you with
the rules for grading as shown in the table below. Write a C program to help
implement the grading system. (10 marks)

Page 2 of 4
Grades Score
A 70-100
B 60-69
C 50-59
D 40-49
E(Fail) Below 39

i. Prompt the user to enter marks for 3 subjects of your choice.


ii. Find the average of the marks.
iii. Use an if..else condition to decide the grade based on the average of
the marks.

QUESTION THREE: (20 MARKS)

a) Volume of a cylinder is given by the formula below. Write a C function to find


the volume of the given cylinder. Prompt the user to enter radius and height
(10 marks)

b) Write a C program to convert temperatures to and from Celsius, Fahrenheit. Use


the provided formula below (10 marks)

Page 3 of 4
QUESTION FOUR: (20 MARKS)

a) Write a C program that computes the area and perimeter of a rectangle. Prompt the
user to enter the length and width of the rectangle (10 marks)

b) Rewrite the following while loop using a for loop. (5 marks)

int i=1;
while(i<=10){
if(i<8&&i!=2||i%4!=0)
printf("%d",i--);
i++
}
c) Write a C program to check if a number is divisible by 11 or not (5 marks)

QUESTION FIVE: (20 MARKS)

a) Draw up a flowchart for entering a student marks, process and provide Output. If
the marks are greater than 40 and repeat if the total marks in less than 40.
(10 marks)
b) An electric motor rotates 1000 times in a minute. every time it rotates it moves a
robot 2cm from its current location. Write a c program that will show distance in M
that the robot will have covered one hour after the motor started rotating.
(10 marks)

Page 4 of 4

You might also like