0% found this document useful (0 votes)
141 views10 pages

Procedural Programming in C Exam

The document is an examination paper for the course COMP 211 Procedural Programming in C at Botswana International University of Science and Technology. It consists of multiple choice and written answer questions worth a total of 70 marks. The paper is divided into three sections: Section A contains 20 marks of multiple choice questions; Section B contains 30 marks of written answer questions; and Section C contains written answer questions. The questions cover topics related to C programming including functions, arrays, structures, files and file handling. Candidates are instructed to answer all questions, show working, and write answers in the provided booklet.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views10 pages

Procedural Programming in C Exam

The document is an examination paper for the course COMP 211 Procedural Programming in C at Botswana International University of Science and Technology. It consists of multiple choice and written answer questions worth a total of 70 marks. The paper is divided into three sections: Section A contains 20 marks of multiple choice questions; Section B contains 30 marks of written answer questions; and Section C contains written answer questions. The questions cover topics related to C programming including functions, arrays, structures, files and file handling. Candidates are instructed to answer all questions, show working, and write answers in the provided booklet.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Botswana International University of Science and

Technology
End of Semester 1 Examination 2021/2022

__________________________________________________
Course code: COMP 211
Course Title: Procedural Programming in C
Total Marks: 70
Date: Time:
__________________________________________________________________________________

Time allowed 2hrs 00 minutes


The following items are provided:
 One examination paper (7 pages in total including the cover page)
 Examination answer book

Candidates must answer all questions from sections A , B and C


 All answers must be written in the answer book(s) provided.
 All rough work must be written in the answer book(s) provided.
 A line should be drawn through any rough work to indicate to the examiner that it is not part
of the work to be graded
 Black or blue pen must be used for writing answers and pencil for all drawing and sketches.
 Ensure that you have the correct number of pages on your exam question paper.
1
Page

Procedural Programming in C-COMP 211


SECTION A: Answer all questions (20 marks)

(Multiple Choice)

Write all your answers in the exam answer booklet provided

1. What is a program?
a. A set of instructions
b. A programming language
c. A compiler
d. A machine language
2. Which of the following is false about compilers?
a. A special program that converts instructions into machine language
b. It takes instructions as inputs
c. The compiler follows the I-P-O cycle
d. The output of a compiler is high level language
3. Which of he following is false about a pseudo code?
a. Provides a detailed template to programmers
b. Is written in a formally styled English language
c. Can represent a high level language
d. Is used as an initial step in the process of developing a program
4. Which of the following is a control statement that allows us to make a decision from a
number of choices?
a. If statement
b. If-else statement
c. Nested if-else statement
d. Switch statement
5. Which of the following is not a control statement?
a. If statement
b. If-else statement
c. For loop
d. Switch statement
2
Page

Procedural Programming in C-COMP 211


6. What is the output of the following code?
#include<stdio.h>
void main()
{
int x =5;
int y;
y = (x>5?7:2);
printf(“%d”,y);
}
a. 5
b. 7
c. 2
d. The code will give an error message

7. Which of the following is not a keyword in C?


a. Volatile
b. Register
c. Enum
d. Structure
8. Which of the following is not a type of a looping statement?
a. For loop
b. If else loop
c. While loop
d. Do-while loop
9. What is the output of the following code?
#include<stdio.h>
void main()
{
int i;
for(i=1;i>5;i--)
printf(“%d”,i);
}
a. 1234
b. 12345
c. 4321
d. No output
10. What is the output of the following code?
#include<stdio.h>
void main()
{
int i = 0;
{
printf(“%d”,i);
}while(i!0);
}
a. No output
b. 0
c. Error message will show
d. Non of the above
11. Which of the following is not a function defined under stdio.h header file?
a. Printf()
3

b. Scanf()
Page

c. Fopen()
d. Clrscr()

Procedural Programming in C-COMP 211


12. In the following C code, which is the function prototype?
#include<stdio.h>
void message();
void main() {
message();
printf("I am in main function");
}
message()
{
printf(" i am in message function"); }

a. void message()
b. message()
c. void main()
d. Non of the above
13. Which of the following is not a system defined function.
a. Display()
b. Main()
c. Printf()
d. Scanf()
14. Suppose you are given the following array, what is the value of idNum[5]?
int idNum[7] = {2, 4, 6, 8, 10, 12, 14};
a. 10
b. 5
c. 12
d. Non of the above
15. How many elements are in the following array?
int a[4][5];
a. 4
b. 5
c. 20
d. 9
16. Given the following string, what is the value of surname[5]?
char surname[] = “BREAD”;
a. D
b. No value
c. \0
d. /0
17. Given the following structure, which is the structure variable?
struct housePlan {
float length, width;
char typeOfHouse;
}house1;

a. struct housePlan
b. house1
c. foat length,width, char typeOfHouse
d. Non of the above
18. Considering the structure in Question 17, which is the proper way of accessing the
width value?
a. housePlan.width
b. house1.width
4

c. width.house1
Page

d. House.width
e.

Procedural Programming in C-COMP 211


19. Under files, what is the function of getc() function.
a. Open an existing file
b. Reads a character from a file
c. Reads a set of data from a file
d. Reads data from the keyboard

20. Which of the following represents a mode for opening a file for reading and writing?
a. r
b. w
c. a
d. r+

END OF SECTION A

5
Page

Procedural Programming in C-COMP 211


SECTION B: Answer all questions (30 marks)

Write all your answers in the exam answer booklet provided

1. What is the functions of the following string functions? [ 4 marks]


a. strlen()
b. strcpy()
c. strcat()
d. strcmp()
ANS:

Function
Purpose
Name
Calculates the length of
strlen()
string
Copies a string to another
strcpy()
string
Concatenates(joins) two
strcat()
strings
strcmp() Compares two string
2. a. Define a flowchart [2 marks]
b. What does the following two symbols represent in a flowhart [2 marks]
i.

ii.

ANS: A flowchart is a graphical representation of an algorithm.


2 b. i = processing
ii = procedure or subroutine
3. a. Explain the functions of fopen() and fclose in file handling. [2 marks]
b. Explain the functions of the following file handling modes. [2 marks]
i. r
ii. w
ANS:
3a.
fopen() create a new file or open a existing file
fclose() closes a file
3b.
r opens a text file in reading mode
w opens or create a text file in writing mode

4. Write a program that gets an integer from the user and print the integer to the
screen. [ 4 marks ]
Ans:
6
Page

#include<stdio.h>
void main()

Procedural Programming in C-COMP 211


{
int number;
printf(“Enter an integer number”);
scanf(“%d”,&number);
printf(“\nThe number you entered is %d”,number);
}
Correct complete code = 4 marks

5. a. Define a function? [ 2 marks]


b. State any two advantages of using functions [ 2 marks]
c. List the two types of functions [2 marks]
ANS 6a: A function is a block of statement that perfom a particular task
ANS 6b: Advantages of functions

 Modular programming
 Length of source program can be reduced
 Easy to locate and isolate faulty functions
 Functions can be used by other programs
ANS 6c. User defined functions and system defined functions
6. a. Define an array? [ 2 marks]
ANS: An array is a collection of elements of the same type that are referenced by a
common name. All the elements of an array occupy a set of contiguous memory
locations.
b. Give an example of an array initialization of type integer with a size of 5,the
name of the array is age. [ 2 marks]
ANS: int age[5] = {2,10,33,24,65};
7. A. What is a structure? [ 2 marks]
B. Give an example code of a structure of your choice with 2 structure members.
[ 2 marks]
ANS: A structure is a collection of variables of different data types under a single
name.The variables are called members of the structure.
struc student
{
Char name[20];
Float marks;
}student1;

END OF SECTION B
7
Page

Procedural Programming in C-COMP 211


SECTION C: Answer all questions (20 marks)

Write all your answers in the exam answer booklet provided


QUESTION 1:

a. Draw a flowchart that find out the sum of two numbers [5 marks]

ANS:

b. Write a program to accept 2 integer numbers from the user and find sum of the
numbers. Use functions. Have a function called sum. [5 marks]

8
Page

Procedural Programming in C-COMP 211


Correct declaration variables used = 1 marks
Function prototype = 1 marks
Function definition = 2 marks
Function call = 1 marks

QUESTION 2:
a. Write a code that prints values from 1 to 3 using for loop. [ 5 marks]
ANS:
#include<stdio.h>
void main()
{
int I;
printf(“The output values are\n”);
for(i=1;i<=3;i++)
{
printf(“%d\n”, i);
}
return 0;
}
Correct complete code = 5 marks

b. Write a program that gets two integer numbers from the user and check which
of the numbers is greater using if else statement. [ 5 marks]
Ans:
#include<stdio.h>
void main()
{
int number1, number2;
printf(“Enter two integer numbers”);
scanf(“%d%d”,&number1,&number2);
if(number1>number2)
printf(“\n number1 is greater than number2”);
else
printf(“\n numbe2 is greater than number1”);
}
Correct complete code = 5 marks
9
Page

Procedural Programming in C-COMP 211


END OF SECTION C

END OF EXAMINATION PAPER

10
Page

Procedural Programming in C-COMP 211

You might also like