0% found this document useful (0 votes)
24 views7 pages

Exam22 Past Paper

This document outlines the end-of-semester examination details for the Principles of Programming course at Mbale University of Science and Technology. It includes instructions for the exam format, sections, and rules, as well as specific questions related to C programming concepts. The exam consists of compulsory and optional questions covering various programming topics and practical coding tasks.

Uploaded by

Kalule Cyprian
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)
24 views7 pages

Exam22 Past Paper

This document outlines the end-of-semester examination details for the Principles of Programming course at Mbale University of Science and Technology. It includes instructions for the exam format, sections, and rules, as well as specific questions related to C programming concepts. The exam consists of compulsory and optional questions covering various programming topics and practical coding tasks.

Uploaded by

Kalule Cyprian
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/ 7

MBARARA UNIVERSITY OF SCIENCE AND TECHNOLOGY

FACULTY OF COMPUTING AND INFORMATICS

End of Semester One Examination for the Degree of

Bachelor of Computer Science/ Information Technology

Course Code: CSC1102/ BIT1103

Course Name: Principles of Programming

Course Year: One

Academic Year 2021/2022

Date: 12th April, 2022

Duration: Three hours

Time 2:00 P.M. – 5:00 P.M.

Instructions:

1. The paper has two sections: A and B.


2. Section A is Compulsory and carries 40 marks.
3. Attempt any three out of the four questions in section B. Each
question carries 20 marks.
4. Begin each question of Section B on a new page.
5. This is not an Open Book Examination – Candidates should not
consult any Reference Material During this sitting.
6. No programmable Electronic device will be allowed in the
examination room
7. Any form of Examination Malpractice is prohibited and when
committed, Examinations Regulations section 2.4.9 shall be applied.
8. Do not Write anything on the Question Paper- Any kind of rough
work should be done at the end of the answer booklet provided.
Section A

Instruction: Attempt all questions

Part I

1. What is the output of this C code?


2 marks
#include <stdio.h>
int main()
{
printf(Hello World! %d \n, x);
return 0;
}
a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!
2. What is the output of this C code?
2 marks
#include <stdio.h>
int main()
{
int y = 1000;
y = 34;
printf("Hello World! %d\n", y);
return 0;
}
a) Compile time error
b) Hello World! 34
c) Hello World! 1000
d) Hello World! followed by a junk value
3. Which of the following is not a valid variable name declaration?
2 marks
a) float PI = 3.14;
b) double PI = 3.14;
c) int PI = 3.14;
d) #define PI 3.14
4. What will happen if the below program is executed?
2 marks
#include <stdio.h>
int main()
{
int main = 3;
printf("%d", main);
return 0;
}
a) It will cause a compile-time error
b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping
5. What is the problem in following variable declaration?
2 marks
float 3Bedroom_Hall_Kitchen;
a) The variable name begins with an integer
b) The special character ‘;‘
c) The special character ‘t’
d) All of the mentioned
6. What is the output of the following code snippet?
2 marks
#include<stdio.h>

main()
{
int a = 5;

a++;
printf("%d", ++a);
}

a) 5 b) 6 c) 7 d) 4

7. C programs are converted to machine language with the help of


2 marks
a) Editor b) Compiler c) Operating System d) None of
the above

8. Where does execution of a C program begin from?


2 marks
a) Preprocessor directives
b) main
c) return
d) variable declaration
9. Comment on the output of this C code?
2 marks
#include <stdio.h>
int main()
{
int ThisIsVariablename = 12;
int ThisIsVariableName = 14;
printf("%d", ThisIsVariablename);
return 0;
}
a) The program will print 12
b) The program will print 14
c) The program will have a runtime error
d) The program will cause a compile-time error due to redeclaration

10. What will the following code output?


2 marks
#include <stdio.h>
#define A 4+3
int main()
{
int c = A * A ;
printf(“%d”, c);
return 0;
}
a) 31 b) 14 c) 19 d)
12

Part II

Write the general structure (syntax), give an example and explain the given
example of the following C concepts
4 marks each

a) if else statement
b) switch statement
c) do while loop
d) structure definition
e) conditional statement
Section B (Choose any three questions)

Question one

a) Write a program that finds the largest and the smallest number of the
two numbers input by the user.
8 marks

b) Write one useful program of your choice to demonstrate a meaningful


use of the following statements as applied to loops

i) break
3 marks
ii) continue
3 marks

c) Write a program that prints the following on the screen(use loops)


6 marks
54321

54321

54321

Question Two

a) Write an if statement that assigns the value of x to the variable y only


if x is between 1 and 10.
2 marks
b) To what value does each of the following expressions evaluate?
i) (3 + 2 * 3/2 + 5)
2 marks
ii) 5 % 2 * 3 - (2 + 2)
2 marks
iii) (7 == 6)
2 marks
c) Fix the following program so that it runs correctly (Edit to remove
errors, write a comment on the line you have edited).
4 marks
/* a program with problems...
#include <studio.h>
int x= 1:
main[]
{
if( x = 1);
printf(" x equals 1" );
otherwise
printf( x does not equal 1);
return 0
}

d) Write a program that requests for three integers from the user and
displays the sum.
8 marks

Question Three

a) Write a function prototype for a function named if_you_fail () that


takes two type int arguments and returns a type int to the calling
program. 2 marks

b) Write a program that finds and displays prime numbers in the range of
1 to 20 and also displays how many they are at the end of the
program. 8 marks

c) Write a program that requests marks from a user and keeps asking the
user to enter a valid mark as long as the mark entered is greater than
100 or less than 0. The program should print ‘’Retake” if the mark is
below 50, print “excellent ” if the mark is 75 to 100 and print ”
Passed” if the mark is 50 to 74 . The program should accept marks for
up to 100 students but the user can type -99 to end the loop if the
students in the class are below 100 and all the marks have been
entered.
Hint: the marks should be kept in an array
10 marks
Question Four

a) Write a program that reads and display all names stored in a file
named NAMES.txt
6 marks

b) Write a code fragment to demonstrate use dynamic memory allocation


with malloc () and free() functions.
4 marks

c) Write a program that stores marks of 10 course units for 20 students


and displays them in alphabetical order according to the first name.
10 marks

“Remember to always read and write”

You might also like