BIT 2123 Structured Programming
BIT 2123 Structured Programming
[4 marks]
c) State with a reason whether the following statements are true or false
i. Every c program begins execution with the main function
ii. C considers the variables name and NAME the same
iii. The modules ( %) operator can only be used with interger operands
iv. Array name acts as a pointer to the first element of an array
[4marks]
i. Strlen
ii. Strcpy
iii. Strcmp [6 marks]
e) Explain 4 rules of naming variables in C programming
[4 marks]
f) With an example show how to declare and initialize an array that holds five elements
of type int
[4 marks]
g) Explain the function of the following functions
i) printf()
ii) scanf()
[4 marks]
Question 2
a) Using a while loop write a program write a program that prints the sum of all odd
integers between 1 and 100
(6 marks)
b) Using examples explain two ways of declaring constants.
(4 marks)
c) Write a C program that prompts the user to enter the radius of a sphere and computes
the volume and the surface area of the sphere. Your program should display the volume
and the surface area of the sphere in a suitable format. Define pi as a constant.
Hint
Volume = ¾ *pi*radius3
Surface area =4*pi*radius2
(6 marks)
d) State and explain 4 classes of operators in C
(4 marks)
Marks Grade
0 to 39 E
40 to 49 D
50 to 59 C
60 to 69 B
70 and above A
Required
Write a program that receives a mark through the keyboard the program then outputs the
relevant grade on the screen.
(8 marks)
b) Using the for loop write a program that outputs a mathematical table of size 10 on the
screen
(6 marks)
c) Write a C program that initializes a mathematical table of size 10 in a two dimensional
array.
(6 marks)
a) By use of an example illustrate the difference between pass by value and pass by
reference. Explain the reasons for your program output
[6 marks]
b) i) Explain the function of the following
fopen()
fclose()
[4 marks]
ii) Write a program that opens a file called student.txt for writing. The program then
outputs the following in the file A, B, C, D, E .The program then closes the file.
[10 marks]