0% found this document useful (0 votes)
385 views5 pages

CCS 2101 Computer Programming 1 Question paperEEE& BED

The document provides instructions for a computer programming exam for students taking a Bachelor of Science degree in Electrical and Electronic Engineering or Bachelor of Education. It outlines 4 questions with subquestions that assess knowledge of C programming concepts like operators, data types, control structures, functions, pointers, and the compilation process. Students are asked to write code snippets, trace programs, define terms, distinguish between programming elements, and more. The exam tests a range of foundational programming and problem-solving skills.

Uploaded by

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

CCS 2101 Computer Programming 1 Question paperEEE& BED

The document provides instructions for a computer programming exam for students taking a Bachelor of Science degree in Electrical and Electronic Engineering or Bachelor of Education. It outlines 4 questions with subquestions that assess knowledge of C programming concepts like operators, data types, control structures, functions, pointers, and the compilation process. Students are asked to write code snippets, trace programs, define terms, distinguish between programming elements, and more. The exam tests a range of foundational programming and problem-solving skills.

Uploaded by

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

DEDAN KIMATHI UNIVERSITY OF TECHNOLOGY

University Examinations 2020/2021

FIRST YEAR SEMESTER 2 EXAMINATION FOR THE DEGREE OF BACHELOR


OF SCIENCE IN EEE and BED

CCS 2101: Computer programming 1

DATE: APRIL 2020 TIME: 2 HOURS

Instructions: Answer Question 1 and Any Other Two.

Question 1: (30 Marks)


(a) Distinguish between each of the following pairs of terms [4 Marks]
I) Operator and operand
II) Source code and object code
(b) Explain the meaning of the following terms [6 Marks]
I) Pseudo code
II) Compiler
III) Algorithm
(c) What are keywords in a programming language?Give an example. [2 Marks]
(d) Sample the following code snippet and answer the following questions:
int n[5]={32,27,64,18,25};
int i;

printf(“%s%13s\n”, “Element”, “Value”);


/*Output contents in tabular format */

For (i=0; i<10; i++)


{
Printf(%7d%13d\n, i, n[i]);
}

I) Write the output of the program [3 Marks]

II) What is the purpose of the literals - %s%13s\n in the program? [2 Marks]
(e) Briefly describe the difference between each of the following pairs of operators as used in
C language: [6 Marks]
I) /= and +=
II) = = and !=
III) && and | |
(f) Why is linking necessary in a C program? [2 Marks]
(g) Describe the use of the printf()and the scanf() methods used in a C program [3 Marks]
(h) Explain the meaning of each of the following function prototypes [2 Marks]
I) int f(int a);
II) void g(long a, short b);

Question 2: (15 Marks)


a) What is a pointer? [1 Marks]
b) Draw a flowchart to illustrate the following program: [4 Marks]
#include<stdio.h>
void main()
{
int mark;
printf(“\n Enter the mark: \n”);
scanf(“%d”, &mark);
if(mark < 40)
printf(“\n You have failed! \n”);
else
printf(“\n You have passed!\n”);
}
c) C Language statements, labels, arrays e.t.c. are separated by special characters
known as delimiters. Enumerate the use of the following delimiters in C language
construct [4 Marks]
i. #
ii. [ ]
iii. { }
iv. ;
d) Suppose a, b, c are integer variables that have been assigned the values a = 8, b and
c = - 5. x, y, z are floating point variables with values x = 8.8, y = 3.5, z = - 0.5
Determine the value of each of the following expressions: [6 Marks]
i. (x / y) + z
ii. 2 * b + 3 * (a – c)
iii. (a * c) % b

Question 3: (15 Marks)


a) Write down the program that will declare an initialized array of FIVE integer elements and uses
the for statement to add up all the elements. The total should be displayed to the user.
[4 Marks]
b) Rewrite the following program using the switch construct [5 Marks]
#include<stdio.h>
main()
{
char grade;
printf(“Enter the Grade:”);
scanf(“%c”, &grade);
if(grade == ‘A’)
printf(“Excellent !\n”);
else if(grade == ‘B’)
printf(“Good !\n”);
else if(grade == ‘C’)
printf(“Fair !\n”);
else if(grade == ‘D’)
printf(“Poor !\n”);
else if(grade == ‘E’)
printf(“Very Poor !\n”);
else
printf(“Wrong Entry !, Enter a grade between A – E \n”);
}
c) Write a declaration of a structure called account with account_number, first_name last_name
and balance as its fields [2 Marks]
d) With the aid of a diagram, briefly illustrate the compilation process of a C program
[4 Marks]

Question 4: (15 Marks)

a) Distinguish between the indirection operator (*) and the address operators (&) as used
with pointers [3 Marks]
b) Give the meaning of the following components of a C program [ 4Marks]
i) Preprocessor directive
ii) Declaration
iii) Comment
iv) Header File
d) What is the output of the following program? [3 Marks]
#include<stdio.h>
main()
{
int pica = 0, delta = 0;
While(pica <= 20)
{
if(pica % 5 == 0)
{
delta += pica;
printf(“\n %d ”, delta);
}
delta++;
}
}
e) Body Mass Index is calculated by dividing a person’s weight (in kgs) by the square of their
height (in meters). Write a program in C that asks a person for his/her weight, calculates
the body mass index and displays it. [5 Marks]

You might also like