0% found this document useful (0 votes)
9 views4 pages

C Programming UE-1

The document outlines an examination paper for the course 'Principles of Computer Programming' covering various programming concepts and error types. It includes instructions for answering questions, programming tasks, and definitions related to variables, loops, functions, and sorting. Additionally, it provides sample answers for some questions to guide students in their responses.

Uploaded by

deowelsaguge
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)
9 views4 pages

C Programming UE-1

The document outlines an examination paper for the course 'Principles of Computer Programming' covering various programming concepts and error types. It includes instructions for answering questions, programming tasks, and definitions related to variables, loops, functions, and sorting. Additionally, it provides sample answers for some questions to guide students in their responses.

Uploaded by

deowelsaguge
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/ 4

End of Semester I/Res-sit Examination Solved Summary: Mar, 2022 iii.

iii. Run time Error occurs when attempting to perform an


invalid operation, detected during program execution that
Course Code: CSS 112
prolong the program execution. Example perform an
Course Title: Principles of Computer Programming illegal operation, such as dividing a number by zero.

Programme: BSc. ITS I, BSc. ICTM I, BSc. AS I, BSc. ICTB I & BSc.
c) Using your knowledge in programming, write a C program
EDU(MICT) I
which asks for (5) integer numbers, then your program
compare those numbers. If a number is divisible by 2 then the
number is first added by 1 and the resulting is added to a
INSTRUCTIONS
variable sum otherwise a number is first subtracted by 2 and
1. There are FIVE (5) question in this paper resulting is added to a variable sum. Display result(6.5 Marks)
2. Answer ANY FOUR Questions Possible answer:

QUESTION ONE (12.5 MARKS)


a) Define Global, local and formal variables (3 Marks)
Possible answer:
Global variable is a variable defined outside the subroutine or
function. It has a global scope means it holds its value
throughout the lifetime of the program. It can be accessed
throughout the program by any function defined within the
program, unless it is shadowed.
Local variable is a type of variable declared within
programming block or subroutines. It can only be used inside
the subroutine or code block in which it is declared.
Formal variable is the variable within the function which
receive the passed data. QUESTION TWO (12.5 MARKS)
b) Describe three types of errors in programming (3 Marks) a) What is a loop? (2.5 Marks)
Possible answer: Possible answer:
i. Syntax Error is the type of error caused by violation of the Is a sequence of instructions that is continually repeated until
C grammar rule detected during program translation a certain condition is reached.
(compilation). b) Using if statement and switch statement, create a Swahili-
ii. Logic Error An error caused by following an incorrect English dictionary for the days of the week depending on the
algorithm. choice of the language, e.g. if the value entered is 1 and
language choice is English, then your program prints out c) Using a while loop, write a C program which asks for integer
Monday (5 Marks) number from the keyboard until when 77 is pressed.(5 Marks)
Possible answer:
Possible answer:

QUESTION THREE (10 MARKS)


a) What is a void function? (1 marks)
Possible answer:
Void function is a stand-alone statement in which does not
return any value.
b) Define three functions, min(), max(), and diff(). Write a C QUESTION FOUR (12.5 MARKS)
program which will create an array M of twenty integers from
By defining the pointer *p pointing to the first value of an array
the keyboard. Using the functions defined, display the
A[15], write a C program which will find the sum of all numbers
difference between minimum and maximum. (11.5 Marks)
divisible by a given number n.
Possible answer: Possible answer:

QUESTION FIVE (12.5 MARKS)


a) What is Sorting (1.5 Marks)
Possible answer:
Sorting is the process of arranging elements either in
ascending (or) descending order.
b) Given five (5) first names of students in your class, write C
program which sorts those names in alphabetic order.
(11 Marks)
Possible answer:

©2022, September 9. Mtui, S.M.

You might also like