DIT 305 PROGRAMMING METHODOLOGY.

UNIVERSITY EXAMINATIONS: 2013/2014
ORDINARY EXAMINATION FOR THE DIPLOMA IN
INFORMATION TECHNOLOGY
DIT 305 PROGRAMMING METHODOLOGY
DATE: AUGUST, 2014 TIME: 1½HOURS
INSTRUCTIONS: Answer Any Three Questions.

QUESTION ONE
(a) Briefly explain the program control structure used in the following code snippet,
hence state the output.
int n,i;
n=17;
i=3;
printf(“%d\n”,n);
n+=i;
printf(“%d\n”,n);
n*=i;
printf(“%d\n”,n);
n-=i;
printf(“%d\n”,n);
n%=i;
printf(“%d\n”,n);
[7 Marks]
2
(b) Identify the error(s) in the following code:
#include <stdio>
int main()
{
int n,i;
n=17;
for(i=0;i<=n;);
{
printf(“%d\n”,n);
}
}
[4 Marks]
(c) Rewrite the following code using if…else statement.
#include <stdio.h>
int main()
{
int n,x;
n=17;
printf(“Enter value of x:\n”);
scanf(“%d”,&x);
(x>n)?printf(“%d\n”,n+1):printf(“%d\n”,n+2);
return 0;
}
[9 Marks]
QUESTION TWO
(a) Differentiate between the following terms as used in c programming
[i]. Local variable and global variable [2 Marks]
[ii]. Rvalue and Lvalue [2 Marks]
[iii]. Literal constant and symbolic constant. [2 Marks]
(b) Write a program in c that uses three functions sum(), avg() and main() where sum
calculates the sum of two floating point values passed to it by main function. The
avg() function then calls the sum so as to get the numerator/total and calculates the
average. Both the sum and average results are returned to the main function which
displays the output in one decimal place. [10 Marks]
(c) Write the following mathematical expressions in c.

QUESTION THREE
(a) For each of the following kinds of information, state the most suitable data type you
would use in a c program.
[i]. Number of employees in an organization [2 Marks]
[ii]. A student letter grade [2 Marks]
[iii]. Currency exchange rate [2 Marks]
(b) State and explain any two operators used with pointers in a c program. [6 Marks]
(c) Define an array as used in a c program, hence use your knowledge of arrays to state
and explain the output of the following program.
#include <stdio.h>
int main()
{
int i;
char lett[]={‘U’,’N’,’I’,’V’,’E’,’R’,’S’,’I’,’T’,’Y’};
printf(“%c”,lett[0]);
printf(“%c”,lett[1]);
printf(“%c”,lett[7]);
printf(“%c”,lett[8]);
printf(“%c”,lett[9]);
printf(“\n”);
return 0;
} [8 Marks]
QUESTION FOUR
(a) Write a program in c that prints even numbers between 1 and 1000.
[6 Marks]
(b) A researcher has asked you to write a program in c that prints responses for a
questionnaire using likert scale after the user types the option from the keyboard
using a criteria shown below.

[10 Marks]
(c) Outline four advantages of imperative programming paradigm. [4 Marks]
QUESTION FIVE
(a) Write a program in c that calculates product table of numbers from 1 to 6 as shown
using nested for loop.

[10 Marks]
(b) Describe any FIVE characteristics of a good programming language. [10 Marks]

(Visited 117 times, 1 visits today)
Share this: