Structured Programming
Structured Programming
Instructlons:
GENERAL
FILE HANDLING IN C
,dt.
"1j.. lflr 1 .(.J>'l ~l, ~ l >
1Nl v i:l{ 1 ,,·lt\ 11\! I.)
),-,½ MG.',~,
l\ ltl ll 11 t l<e11,ra
1
~
U 11iversity
~ )
BBIT/BSC IT
REGULAR
b) Define the following terms:, 'iD/\..1 c• ,,,\ r,> (•'\ , n t"'' L'f,n (10 Marks)
i. Algorithm , {~-! G\ 1•'J r, lll'
c) Write a c program that asks the user to enter an integer and this program
will generate the multiplication table up to 5. (5 Marks)
c.0 \"-h1 k C\ r',,,J'''"' h:J ,f o r'j root! 01 Cl ~UC!dn.h c.. f q,uei ~o•'l (cl n') a,~-0
QUESTION THREE (20 Marks)
~ o,I ~ f?
e) Write a program that will prompt the user to enter a number. The program
determines the square root of the number through a built-in function and
displays the result on the screen. (5 Marks)
/(
' 1/'v
J
itJI '\-
a) Explain the term nested -if control structure. I I 111 I I
1 11
! I( 1
l l j 1f (lf·!
t~< , I
(2 Marks)
, 1' \
-~c) Write a C program that sums all integers from 10 to 70. Use
the for statement. 1 (5 Marks)
/; /
t I
d) The table below shows the charges applicable to different an¾ounts of water
consumed by clients in a particular town. /,., 1
Volume of water
Consumption in Ksh
consumed in M3
I. 0-16 200
'\ C
II . 10-20 350
111 . 20-30 500
IV. Over 30 1000
In addition to the consumption, the amount of the water bill will consist of a
standing charge of Ksh 200 and a sewerage fee equivalent to 20% of the
consumption.
Write a C program that prompts a user to enter the volume of water
consumed. The program then computes and outputs the amount of the
water bill. Use if.. . else control structure. (10 Marks)
l --1
I··'
1'
I , ~
!t
'l J'
j
Mount Kenya '~ ~JUniversity
UNIVERSITY EXAMINATION 2016/2017
BIT/BBIT /BIT
VIRTUAL CAMPUS
INSTRUCTIONS: ANSWER ALL QUESTIONS IN SECTION A AND ANY OTHER TWO FROM
SECTION B
SECT!ON A (Ccmpu!sory)
a) List four Rules and Conventions for naming variables and constants in C.
[4 marks]
b) Explain using examples how to declare variable and initialize variable .
[4 marks]
c) Difference between union and structure. [4 marks]
d) Distinguish between gets() function and puts() with the help of an example.
[6 marks]
e) Use a flow chart to explain the three main program control structures
[6 Marks]
f) Differentiate between the following programming concepts [6 marks]
i. Loosely typed and strongly typed languages
ii. Pseudo code and Algorithms
· Linking and compiling
a) Write a program in C to find the area and perimeter of a circle. [10 marks]