NOTE: There are 11 Questions in all.
Question
1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the
space provided for it in the answer book supplied and nowhere else.
Answer
any THREE Questions each from Part I and Part II. Each of these questions
carries 14 marks.
Any
required data not explicitly given, may be suitably assumed and stated.
Q.1 Choose
the correct or best alternative in the following: (2 x 8)
a.
In
a C program, constant is defined
(A) before main.
(B) after main.
(C) anywhere, but starting on a
new line.
(D) None of the above.
b.
If
abc is the input, then the following program fragment results in
char
x, y, z;
printf(%d,
scanf(%c%c%c, &x, &y, &z));
(A) a synax error.
(B)
a fatal error.
(C) segmentation violation.
(D) printing of 3
c. If integer
needs two of storage, then maximum value of a signed integer is
(A)
(B)
![]()
(C)
(D)
d. Output of the following program fragment is
x = 5;
y
= ++x;
printf(%d%d, x, y);
(A) 5, 6 (B)
5, 5
(C) 6, 5 (D) 6, 6
e. Output
of the following program fragment is
int x =2, y = 5, z = 1, a;
a
= x < y < z
printf(%d, x);
(A)
1 (B) 0
(C) error (D) 5
f.
Which of the following is not a valid
character constant?
(A) a (B) $
(C) \n (D) xyz
g. What
is the output of the following program fragment?
int
a=5, *b =&a;
printf(%d %d, a, b);
(A) 5 5 (B) garbage
(C) 5 Address of b (D)
error message
h. Choose
the correct answer
(A) An entire array can be passed
as argument to a function.
(B) An array is passed to function
by value.
(C) Any change done to an array,
passed as an argument to function will be local to function only.
(D) None of these.
Answer
any THREE Questions. Each question carries 14 marks.
Q.2 a. Write a C program that reads an unsigned
integer X and displays the leftmost digit of it. (6)
b. Given the values of the variables X, Y and Z, write a C program to
rotate their values such that X has value of Y, Y has value of Z and Z has
value of X. Read the values and display after rotation. (4)
c.
Output
the number y = 256.667 under the following format specification.
(i)
printf(%7.2f,
y)
(ii)
printf(%f,
y)
(iii)
printf(8.2e,
y)
(iv)
printf(%e,
y) (4)
Q.3 a. (i)
Why and when do we use #define directive?
(ii)
What
does void main(void) mean?
(iii)
What
is the difference between getchar and scanf functions? (6)
b. Write a C
program using while construct to find out the number of persons in age group
between 40 to 60. Read the ages of 100 persons and print the result. You are
not allowed to use array. (5)
c. Write conditional operators to evaluate the following function
y = 20.5, for x
= 0
y
= 4.8x 3, for x < 10
y = 3x+5, for
x > 10 (3)
Q.4 a. State what (if anything) is wrong with each
of the following statements / segments:
(i) printf
(%f, %d, %s, price, count, city)
(ii)
double root;
scanf (\n%f, root);
(iii) if (p < 0) || (q < 0)
printf(sign is negative);
(iv) while (count != 8);
{
count=1;
sum=sum+x;
count=count+1;
}
Assume that all the variables have been
declared and assigned values. (4x2=8)
b. Write a C program to count the number of
vowels in a given input string. Read the string and display the result. (6)
Q.5 a. Write
a C program to convert any typed input into capital letters. (5)
b. What is the output of the following program?
main()
{int k, x = 0;
for (k=1; k <50; k*=2)
{ x++;
printf(%d ,x);
}
printf(\n x = %d k=%d, x, k);
} (4)
c. Write a C program which uses gets and puts to
double space typed input. (e.g, if input is abcde then output will be a b c
d e). (5)
Q.6 a. (i) What would be the output of the following code segment?
count = 7;
while (count -- > 0)
printf (count);
(ii) Determine how many times the body of loop will be executed?
x = 7;
y = 70;
while (x <= y)
{ x = y / x;
---
--- }
(iii) Change the following for loop to while loop
for (x=1; x<10; x=x+1)
printf(x);
(iv) Determine the value of the following expression
if a=5, b=10 and c = -6
a
< b && a > c (4
x 2 = 8)
b. Write a switch statement that will examine
the value of a char type variable color and print the following messages: (6)
It is Red colour, if color has value either r or R
It is Blue colour, if color has value either b or B
It is Green colour, if color has value either g or G
It
is White colour, if color has any other value
Answer
any THREE Questions. Each question carries 14 marks.
Q.7 a. Define a structure consisting of two floating
point members called real and imaginary. Include the tag complex within the
definition. (3)
b. Declare a one dimensional complex array
called carray of 100 elements. (2)
c. Write a C program to input carray defined
above. Compute the sum of all 100 complex numbers and print it. (9)
Q.8 a. Compare, in terms of their functions, the
following pairs of statements:
(i)
while
and for.
(ii)
break
and goto.
(iii)
break
and continue.
(6)
b. The following set of numbers is popularly
known as Pascals triangle. If we denote rows by i and columns by j, then any
element except boundary elements in the triangle are given by
. Write a C program to calculate the elements of Pascal
triangle for 10 rows and print the result. Few rows have been shown below. (8)
|
1 |
|
|
|
|
|
|
1 |
1 |
|
|
|
|
|
1 |
2 |
1 |
|
|
|
|
1 |
3 |
3 |
1 |
|
|
|
1 |
4 |
6 |
4 |
1 |
|
|
1 |
5 |
10 |
10 |
5 |
1 |
|
. |
|
|
|
|
|
Q.9 a. Write a C function
that fills up an upper left triangle of N N matrix with 1. (6)
b. (i)
Which of the following expressions are valid? If valid, give the value of the expression; otherwise give
reason.
21%
(int) 4.5
(5/3)
*3 + 5 % 3 (2)
(ii) Which of the
following expressions are true
!
(5 +5 >= 10)
10!
= 15 && ! (10<20) || 15>30 (2)
(iii) What is a null
statement? Explain a typical use of it. (2)
(iv) How does a
structure differ from an array. (2)
Q.10 a. Define
a self-referential structure containing the following three members.
(i)
a
40-element character array called name
(ii)
a
structure called stats of type record containing two members {int, float}
(iii)
a
pointer to another structure of this same type called next (6)
b. Write a C
statement that will allocate an appropriate block of memory with ptr (a pointer
to the structure defined above) pointing to the beginning of the memory block. (2)
c. Write short
notes on any THREE of the following topics:
(i)
Structured
programming
(ii)
Top
down approach of program development
(iii)
Program
efficiency
(iv)
Difference
between compiler and interpreter (6)
Q.11 a.
The skeletal outline of C program is shown below:
(i)
Read
the values of a, b and c from the data file sample.old.
(ii)
Display
them on screen.
(iii)
Write
new values to data file sample.new. (6)
b. Explain the meaning
and purpose of the following:
(i)
Template.
(ii)
Size
of operator.
(iii)
typedef.
(iv)
float.
(8)