Programming Fundamentals

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

EXAMINATION

FACULTY OF SCIENCE AND TECHNOLOGY

PROGRAMME(S): DIT/BIT/BCS/BSF/BAV/DAV

SESSION: DAY
MODULE CODE AND TITLE: LEVEL:
Programming Fundamentals 1.2

DATE: TIME:
January, 2024 01:00 PM – 07:00 PM

DURATION: TOTAL MARKS:


6 Hours 100

EXAMINER/ LECTURER: MODERATOR:


Mr. Kasiita Tawfik Ms. Lillian Tamale

INSTRUCTIONS TO THE CANDIDATE/ STUDENT


1. V-class is the ONLY official examination platform.
2. Questions must be attempted in the answer booklet/sheet provided on V-class.
3. All queries should be directed to the examiner, Head of Department, or Dean.
4. You have SIX HOURS to complete this paper. No exam answer sheet shall be accepted
after the 6 hours (the system has closed).
5. This is an OPEN BOOK (Online) examination.
6. Attempt 4 Questions in total. All questions carry equal marks (25 marks each).
7. Section A has TWO COMPULSORY case-based Questions and choose any 2 other
questions in Section B.
8. Read each question carefully before beginning to type/write your answers.
9. Review the grades assigned to each question of the examination and allocate your
time accordingly.
10. Review your answers carefully before submitting your examination.
11. After submitting your exam answer sheet, Cross-Check to ensure your examination was
attached and sent to V-class and received a confirmation message.

1|Page
SECTION A (Compulsory)

QUESTION ONE
a) The following Program code can be used to print multiple lines with a print f statement.

#include stdio.h>
Int main (void)
Print (welcome to C!”);
printf(“Happy coding!”)
Return 0
}
Correct the Program code above and show the Output of the Program
(10 Marks)
b) Write the general syntax of an if else statement in C Programming

(03 Marks)
c) Write an example of a simple code that uses an if else statement

(06 Marks)
d) What is the difference between Lvalues and Rvalues

(03 Marks)
e) Describe three types of operators in C - programming

(03 Marks)

QUESTION TWO
a) What is the use of functions in a c program?

(02 Marks)
b) Briefly explain three data types in C programming and write example codes for each

(15 Marks)
c) The ……… statement is used to make decisions while the ……. is for repeating code
execution.

2|Page
(03 Marks)
d) Write the output of the following program

int main (){


int number=12;
if(number==10){
printf("number is equals to 10");
}
else if(number==100){
printf("number is equal to 100");
}
else{
printf("number is not equal to 10 or 100");
}
return 0;
}
(05 Marks)

3|Page
SECTION B (Attempt Only 2 Questions)

QUESTION THREE
a) The table below shows arrange of grade of marks for an institute

Marks Arrange Grade


90 and above marks A
80 - 89 B
70 - 79 C
60 - 69 D
Below 60 F (Fail)

Use the table above to design up C program that will allow to input a mark of student
from the keyboard and grades it.
(10 Marks)
b) Identify and correct the errors in each of the following statements.
(i) Printf ( “The value is %d\n”, &number);
(ii) scanf ( “%d%d”, & number1, number2);
(iii)if (C < 7); {

Printf ( “ c is less than 7\n”);


}
(iv) if ( c => 7){

Printf ( “c is equal to or less than 7\n”)


}
(08 Marks)
c) Write a simple program to demonstrate how to use functions in C

(07 Marks)

4|Page
QUESTION FOUR
a) Briefly explain the following terms as used in Programming giving an example of each.
(i) Keyword
(ii) Variable
(iii)Identifier
(iv) Comment.

(08 marks)
b) State whether each of the following is TRUE or FALSE. If false, explain why.
(i) Function printf is used to get input from the user…………
(ii) Comments cause the computer to print the text enclosed between /* and */
on the screen when the program is executed…………
(iii)The escape sequence \n when used in a printf format control string causes the
cursor to position to the beginning of the next line on the screen ………
(iv) All variables must be given a type when they are defined……..
(v) C considers the variables number and NuMbEr to be identical .…...

(05 Marks)
c) Write a C programme that can takes the base and height of a triangle as input and prints
it’s area.

(12 marks)

QUESTION FIVE
a) Write a C program that can print the first 20 odd numbers

(08 Marks)
b) Write a C program that can calculate the average marks of four tests

(07 Marks)
c) Write a program using the C compiler which captures the following from the keyboard
and prints them on the screen.

Your Full Name


Your registration number

5|Page
The year of study
Your current University
Concatenates the strings above and output them as one string in the form
Output – “My name is…… Reg no ………. in ……… at …… University”
(10 Marks)

QUESTION SIX
a) Define variable scope.

(02 Marks)
b) Write a Statement in C programming to accomplish each of the following:
(i) Define the variables x, y , z and the result to be of type int.
(ii) Make the program to display text “Enter three integers” to the Screen.
(iii)Prompt the user to enter three integers as keyboard input.
(iv) Calculate the product of x, y and z and store the value in result.
(v) Print “ The product is” followed by the value of the integer variable result.

(12 Marks)
c) What is the difference between a while loop and a do while loop, show a simple code
example

(06 Marks)
d) Write a program to take input of height for three students and print the height of the
tallest

(05 Marks)

6|Page

You might also like