0% found this document useful (0 votes)
0 views3 pages

BIT 2123 Structured Programming

The document consists of various programming questions related to C language, covering topics such as data types, string functions, variable naming rules, structures, and file handling. It includes tasks like writing programs for calculating sums, grades, and handling arrays, as well as explaining concepts like preprocessor directives and function prototypes. Additionally, it addresses the differences between pass by value and pass by reference, and outlines the use of specific functions like printf() and scanf().

Uploaded by

mugocaleb718
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views3 pages

BIT 2123 Structured Programming

The document consists of various programming questions related to C language, covering topics such as data types, string functions, variable naming rules, structures, and file handling. It includes tasks like writing programs for calculating sums, grades, and handling arrays, as well as explaining concepts like preprocessor directives and function prototypes. Additionally, it addresses the differences between pass by value and pass by reference, and outlines the use of specific functions like printf() and scanf().

Uploaded by

mugocaleb718
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

a) Differentiate between the following data types

i. int and char


ii. float and double
[4 marks]
b) Briefly explain the following terms
i. Preprocessor directives
ii. Function prototype

[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]

d) Explain how the following string functions work

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) Explain the difference between a structure and a union


[4 marks]
b) Write a program using a structure called baccount to be used to process the following
details about a bank account
 account_name
 account_number
 minimum_balance
 account_type
The program should allow input of the above details through the keyboard and output the
same on the screen for 20 accounts [10 marks]
c) 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]

Question 3(20 marks)

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)

Question 4 (20 marks)

a) KUCT grades students in an exam as shown in the table below

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)

Question 5 [20 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]

You might also like