ACSC 122
CHUKA UNIVERSITY
UNIVERSITY EXAMINATIONS
EXAMINATION FOR THE AWARD OF DEGREE OF BACHELOR OF SCIENCE IN
APPLIED COMPUTER SCIENCE
ACSC 122: INTRODUCTION TO STRUCTURED PROGRAMMING USING C
STREAMS: TIME: 2 HOURS
DAY/DATE: WEDNESDAY 12/04/2023 11.30 A.M – 1.30 P.M
INSTRUCTIONS:
SECTION A-COMPULSORY
QUESTION ONE (30 MARKS) [COMPULSORY]
(a) Differentiate between the following terminologies in C programming
i) Source code and object code [2 marks]
ii) Compiler and interpreter [2 marks]
(b) Write a program to calculate the factorial of a number entered. (remember: negative
numbers have no factorial, 0 factorial =1) [5 marks]
(c) Explain four qualities of a good algorithm [4 marks]
(d) Scrutinize the following code and then answer the questions that follow:
#include <stdio.h>
int main ()
{
int n[ 10 ]; /* n is an array of 10 integers */
int i,j;
for ( i = 0; i < 10; i++ )
{
n[ i ] = i * 100; /* set element at location i to i *100 */
}
for (j = 0; j < 10; j++ )
{
printf("Element[%d] = %d\n", j, n[j] );
}
return 0;
}
i) Draw a flow chart of the above code. [4 marks]
ii) Write line 1, line 3, and line 5 of the solutions if the code is run [3 marks]
Page 1 of 3
ACSC 122
(e) Name SIX IDEs that can be used for compiling C program source codes. [3 marks]
(f) Answer the following questions with regard to relational operators.
i) Explain what relational operators in C programming are. [2 marks]
ii) Write a simple C code implementing any three relational operators, hence give a
solution the code will provide if run. [5marks]
SECTION B: ANSWER ANY TWO QUESTIONS
QUESTION TWO (20 MARKS)
(a) Name four keywords, hence explain why each is a keyword [4 marks]
(b) Explain two libraries / includes used in C programming using a simple code [4 marks]
(c) Write a C code to test whether a number entered is negative, positive or zero. Hence
return the square of the number [6 marks]
(d) Write a C code that prompts a user to enter a max number and a min number, of which
both of the numbers should be integers greater than or equal to 0. It then prints only the
values that are divisible by 3 between the two numbers inclusively in descending order.
[6 marks]
QUESTION THREE (20 MARKS)
(a) Using appropriate examples, explain the following errors: - [6 marks]
i) Syntax error
ii) Run-time error
iii) Logical error
(b) Explain three reasons why end users need to be involved in system development
[3 marks]
(c) In a certain restaurant, a waiter requires one tray to carry three served plates. Write a C
code that prompts a waiter to enter the number of served plates to carry, hence it
calculates and prints the number of trays to use. Assuming all the served plates are to be
delivered at the same time, and no half tray. (hint: 4 served plates require 2 trays to
carry and not 1.33trays as in ordinary calculations) [5 marks]
(d) Write a C code to display the factors of a positive integer entered by a user. (Factors are
numbers that are divisible by the entered integer. They should be between 1 and that
integer inclusively) [6 marks]
QUESTION FOUR (20 MARKS)
(a) With reference to operator precedence, answer the following questions.
i) Explain the term operator precedence [2 marks]
ii) Arrange the following six operators, separated by commas, from the lowest
to the highest preference. Operators are %, ++, *, &&, | |, ( ) [3 marks]
(b) Explain two purpose of debugging a source code in C [2 marks]
Page 2 of 3
ACSC 122
(c) With an example of a flow chart in each case, explain three decision making
statements used in C programming [6 marks]
(d) Write a code in C that prompts a teacher to enter the number of students in a class. It
then prompts total cat marks for each student, stores them in an array and calculates,
hence display the average mark and the total of all cat marks. [7 marks]
QUESTION FIVE (20 MARKS)
(a) Write the syntax of a DO…WHILE loop, hence explain how it differs with a
WHILE loop. [4 marks]
(b) Explain two rules used when declaring variables. [2 marks]
(c) Using SWITCH decision making statement, write a C code that prompts a user to
enter two integers. The code then prompts a user to select from options 1-3
inclusively. If a user selects option 1 the code returns the sum of the two integers, if
the user selects option 2 it returns the product of the numbers; if the user selects
option 3 it returns the sum of the squares of the numbers. [6 marks]
(d) Figure below show standard playground shapes of various institutions. Use it to
answer a question that follows:
a
c
Y Z
b
Using a function for each of the parts labeled X, Y and Z. Write a C program to
assist the institutions in calculating the total cost of painting their playgrounds, if
1m2 is painted using ksh 150 and a user is to enter distances a, b and c of their
institution in meters. Take pie to be 3.14. [8 marks]
------------------------------------------------------------------------------------------------------------------
Page 3 of 3