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. Literal means
(A) a string. (B) a string constant.
(C) a character. (D) an alphabet.
b. Choose the correct answer
(A) Casting refers to implicit type conversion.
(B) Coercion refers to implicit type conversion.
(C) Casting means coercion.
(D) Coercion refers to explicit type conversion.
c. printf (“%d”, printf (“tim”));
(A) results in a syntax error (B) outputs tim3
(C) outputs garbage (D) outputs tim and terminates abruptly
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. The value of an automatic variable that is declared but not initialised will be
(A) 0 (B) -1
(C) unpredictable (D) none of these
f. Consider the following program
main ( )
{ float a = 0.5, b = 0.7;
if (b < 0.8)
if (a < 0.5) printf (“ABCD”);
else printf (“PQR”);
else printf (“JKLF);
}
The output is
(A) ABCD (B) PQR
(C) JKLF (D) None of these
g. The following program fragment
int *a;
*a = 7;
(A) assigns 7 to a (B) results in compilation error
(C) assigns address of a as 7 (D) segmentation fault
h. A pointer variable can be
(A) passed to a function as argument.
(B) changed within function.
(C) returned by a function.
(D) assigned an integer value.
Answer any THREE Questions. Each question carries 14 marks.
Q.2 a. Write a C program that reads a fixed point real number in a character array and then displays rightmost digit of the integral part of number. (6)
b. Output the number x = 56.1624 under the following format specification
(i) printf (“%7.2f”, x)
(ii) printf (%f”, x)
(iii) printf(“8.2e”, x)
(iv) printf(“%e”, x) (4)
c. Write C statements to read the values of three variables of the type int, float and string and print them if correct data is entered otherwise print “error in input”. (4)
Q.3 a. Write a C program that uses ‘for’ construct to find the sum of the following harmonic series for a given value of n and display the sum.
1 + 1/2 +1/3 +… + 1/n (6)
b. Write conditional operators to evaluate the following function
y = 2.4x + 3, for x <= 2
y = 3x –5, for x > 2 (4)
c. Write a C program fragment using “do…while” construct to print out even numbers between 10 to 100 making sure that two numbers are written per line. (4)
Q.4 a. Given an integer, write a C program that displays the number as follows:
first line : All digits of integer
second line : all except first rightmost digit
third line : all except two rightmost digits
.
.
.
last line : leftmost digit (8)
b. Describe the output of the following C program fragment
main ()
{ int k = 0, x = 0;
while (k < 25)
{ if (k % 5 == 0)
{ x += k;
printf(“%d ”, x);
}
++k;
}
printf(“\nx=%d “, x +k);
} (6)
Q.5 a. Shown below is a Floyd’s triangle. Write a C program to print this triangle (8)
|
1 |
|
|
|
|
|
|
2 |
3 |
|
|
|
|
|
4 |
5 |
6 |
|
|
|
|
7 |
8 |
9 |
10 |
|
|
|
11 |
… |
|
|
15 |
|
|
|
|
|
|
|
|
|
79 |
… |
|
|
|
91 |
b. Given the string “DATA PROCESSING”, write a C program to read the string from terminal and display the same in the following formats.
(i) DATA PROCESSING
(ii) DATA
PROCESSING (6)
Q.6 a. Write a C program to compute the value of sin function. The loop must terminate when the absolute value of the term is less than 0.00001.
(8)
b. Write a switch statement that will examine the value of an integer variable flag and print the following messages: (6)
It is hot weather; if flag has value 1
It is a stormy weather; if flag has value 2
It is sticky weather; if flag has value 3
It is a pleasant weather; otherwise
Answer any THREE Questions. Each question carries 14 marks.
Q.7 a. Define a structure named ‘student’ containing two fields ‘name’ and ‘marks’.
(2)
b. Declare an array of structure having 50 elements of student type. (2)
c. Write an input statement for inputting the marks and the names of 50 students defined as above. (3)
d. Write a complete C program to compute and print the names of those students who have got more than 80 marks. Also print their marks along with their names. (7)
Q.8 a. Write
a recursive function in C to compute the value of
where n is a positive integer and x
has a real value. (7)
b. Write a function ‘exchange’ to interchange the values of two variables say x and y. Illustrate the use of this function in calling program. Assume that x and y are defined as global variables. (7)
Q.9 a. Write a C function that returns 1 if the argument is a prime number and returns 0 otherwise. (7)
b. Write a C function for searching an element in an array of size N. Assume that elements in array are stored in ascending order. (7)
Q.10 a. Explain the declaration int (*p (char *a))[10]; (3)
b. Suppose a member of a structure is a pointer variable. How can the object of the pointer be accessed in terms of structure variable name and the member name? (3)
c. What happens when a pointer to structure is incremented? What danger is associated with this type of operation? (2)
d. Distinguish between the following:
(i) Syntactic error and semantic error
(ii) Run time error and logical error
(iii) Debugging and testing (6)
Q.11 a. The skeletal outline of a C program is shown below:
Read the values of a, b and c from the data file and display them on the screen (3)
b. How the program design and program efficiency related to each other. (2)
c. Given the following program
main( )
{ static int a[5] = {10,20,30,40,50};
void find (int *p);
….
find (a);
….
}
void find (int *p)
{int j, sum = 0;
for (j=3;j<5;++j) sum +=*(p+j);
printf(“sum = %d”, sum);
return;
}
(i) What kind of argument is passed to find?
(ii) What kind of value is returned?
(iii) What value is displayed by print statement within find? (9)