You are on page 1of 4

NATIONAL INSTITUTE OF BUSINESS MANAGEMENT

DIPLOMA IN COMPUTER SYSTEM DESIGN 2009.2

PROGRAMMING WITH C LANGUAGE


12th October 2009, 8.30 a.m. 11.30 a.m.
Answer All questions.
Time: THREE hours.
The marks given in brackets are an indicative of the weight given to each part of the question.

(1)

(2)

Write a single C statement for each of the following :


a)

First reduce the value of A by 1, then find the sum of A and B, and then increment the
value of B by 1. Assign the sum to C.

b)

First increment the value of A by 1, then multiply A by B, and then reduce the value of
B by 1. Assign the product to C.

c)

First increment the value of X by 1, then find the Remainder of X divided by Y, and
then reduce the value of Y by 1. Assign the remainder to Z.

d)

First reduce the value of A by 1, then divide the value of A by B, and then increase the
value of B by 1. Assign the quotient to C.
(8 marks)

Determine the value of each variable after the calculation is performed.


All variables have the value 3 before execution of each statement.
a)
R1 + = ++X1 * --Y1;
b)
R2 * = X2-- + Y2++;
(6 marks)

(3)

Answer the following :


a)
b)
c)
d)
e)
f)
g)
h)

What is the general format of a function definition?


What are the differences between local and global
variables?
What are the differences between while and do while
Repetition Structures ?
What are the Data Types provided in C?
What are the Storage Classes provided in C? Explain
each giving a suitable example.
What is the difference between break and continue?
What happens by the scanf statement?
What are the differences between Recursion and Iteration.
(16 marks)

(4)

Write a program in C to print all the Prime Numbers from 2 to 100.


(10 Marks)

(5)

Write a program in C to input 2 positive numbers and to find the


Greatest Common Divisor (GCD) of the two numbers using
Euclids method.
(10

Marks)
(6)
Write a program in C for the following:
i)

Input data to an array V of length N.

ii)

Sort the data in the array V into ascending order using


'Bubble1 Sort'.

iii)

Input a 'Search Value' and find the position of the search value
in the sorted array using `Binary Search'.
(20 Marks)

(7)

Write a program in C for the following :


i)

Input data to two Matrices U[N, N] and V[N, N] .

ii)

Add the 2 matrices and store the sum in W[N, N].

iii)

Multiply the 2 matrices and store the results in W[N, N].

iv)

Print the results of each of the above.


(12 marks)

(8)

Write the output of the following programs. Each question will carry 3
marks.
i)

ii)

void main()
{
int x = 20, i;
for (i=2; i < 7; ++i)
{
if (i%2 == 1)
x += i;
else
printf("%d\n", x);
break;
}
printf("%d\n", ++x);
}

void main()
{
int i, j, x=0;
for (i = 4; i > 0; i= i + 3)
{
for (j=1; j < i; ++j)
{
x = i + j;
printf("%d\n", x);
}
printf("%d\n", ++x);
}
}

iii)

iv)

void main()
{
int i, j, k, x=0;
for (i=1; i < 5; ++i)
{
for (j=1; j < i; ++j)
{
k = i + j;
if (k % 3 == 0) break;
else if (k % 4 == 0)
printf("%d\n", x);
}
printf("%d\n", ++x);
}
}

void main()
{
int i = 1, x = 40;
while (i < 6)
{
if (i % 2 == 0)
{
x += i;
printf("%d\n", x);
}
++i;
}
printf("%d\n", ++x);
}

v)

vi)

int a = 10, b=20;


int funct1(int);
int funct2(int);

int fun1(int, int);

void main()
{
int x, y;
for (y = 1; y <= 10; y = y + 4)
{
x = funct1(y) * funct2(y);
printf("\n%d\n", x);
}
getch();
}
int funct1(int a)
{
static int b;
b = funct2(a);
return b;
}
int funct2(int c)
{
static int d = 1;
d *= 1;
return (c * d);
}

void main()
{
int count, c, d, a=2, b=3;
for (count =1; count < 4; ++count)
{
c = 3 * count;
d = 2 * count;
printf("\n%d\t%d", fun1(a, c), fun1(b, d));
}
getch();
}
int fun1(int x, int y)
{
return x* y;
}