UNIVERSITY EXAMINATIONS: 2012/2013
FIRST YEAR EXAMINATION FOR THE BACHELOR OF SCIENCE
IN INFORMATION TECHNOLOGY
BIT 1304 PROGRAMMING METHODOLOGY
DATE: DECEMBER, 2012 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO
QUESTION ONE
a) Explain how the following three types of operators are used in a C program giving
examples
i. Relational operators (2 Marks)
ii. Arithmetic operators (2 Marks)
iii. Logical operators (2 Marks)
b) Using an example differentiate between the division operator and the modulus
operator as used in structured programming (4 Marks)
c) Differentiate between source code and object code (2 Marks)
d) Explain the five basic data types used in C (5 Marks)
e) Using a code skeleton differentiate between a function prototype and a function
definition (4 Marks)
i. Define the term structure as used in a c program (2 Marks)
ii. Write the syntax of declaring a structure in C program (3 Marks)
g) Explain how a function works in a C program (4 Marks)
QUESTION TWO
a) Explain the output of the following code snippets
i. main() (2 Marks)
{
int i=5;
printf(“%d%d%d%d%d%d”,i++,i–,++i,–i,i);
}
#define square(x) x*x (2 Marks)
ii. main()
{
int i;
i = 64/square(4);
printf(“%d”,i);
}
b) Write a program using a for loop that calculate the Sum of odd numbers between
1 and 10. The minimum and maximum values should be provided using the
keyboard (6 Marks)
c) A string is called palindrome if it symmetric. In other word a string is called
palindrome if string remains same if its characters are reversed. For example:
asdsa. If we will reverse it will remain same i.e. asdsa. Write a c program to check
if a given string is palindrome number or not (7 Marks)
d) Write the output of the following code (3 Marks)
#include <stdio.h>
#include <conio.h>
struct student {
int id;
char *name;
float percentage;
} student1, student2, student3;
int main() {
struct student st;
student1.id=1;
student2.name = “Angelina”;
student3.percentage = 90.5;
printf(” Id is: %d \n”, student1.id);
printf(” Name is: %s \n”, student2.name);
printf(” Percentage is: %f \n”, student3.percentage);
getch();
return 0;
}
QUESTION THREE
a) Define the term pointer (2 Marks)
b) Write the syntax of declaring a pointer in a C program (2 Marks)
c) Write a program that uses a function to find factorial of a given number (6 Marks)
d) Write a program to generate the Fibonacci series (6 Marks)
e) Explain the syntax of the if …else if statement (4 Marks)
QUESTION FOUR
a) Write a program to find the largest element in an array (5 Marks)
b) Write a simple program that uses a for statement to print the numbers 1 through
20 (4 Marks)
c) Write a C program to reverse a string using pointers (6 Marks)
d) Using integer and modulus operator write a c program to find out sum of digit of
given number (5 Marks)
QUESTION FIVE
a) Explain any four components of a C program (8 Marks)
b) State the rules applied in naming variable (4 Marks)
c) Write a program for swapping two integers (4 Marks)
d) Explain the stages of developing a C program (4 Marks)