Code: C-05 / T-05                                      Subject: PROGRAMMING  & PROBLEM SOLVING THROUGH’ C

Time: 3 Hours                                                              June 2006                                         Max. Marks: 100

 

NOTE: There are 9 Questions in all.

·      Question 1 is compulsory and carries 20 marks. Answer to Q. 1. must be written in the space provided for it in the answer book supplied and nowhere else.

·      Out of the remaining EIGHT Questions answer any FIVE Questions. Each question carries 16 marks.

·      Any required data not explicitly given, may be suitably assumed and stated.

Q.1       Choose the correct or best alternative in the following:                       (2x10)

                

             a.  What is the output of the following C program? 

                                                # include <stdio.h>

main ( )

{

                        int a, b=0;

                        static int c [10]={1,2,3,4,5,6,7,8,9,0};

                        for (a=0; a<10;+ + a)

                        if ((c[a]%2)= = 0) b+ = c [a];

                        printf (“%d”, b);

                       }

 

                  (A)  20                                                 (B)  25

                  (C)  45                                                 (D)  90                                                 

                                                                                                                                                                 

             b.   If a, b and c are integer variables with the values a=8, b=3 and c=-5. Then what is the value of the arithmetic expression:

                   2 *  b + 3 * (a-c)

(A)    45                                                (B)  6

(C)  -16                                              (D)  -1

 

             c.   A global variable is a variable

                  

(A)    declared in the main ( ) function.

(B)    declared in any function other than the main ( ) function.

(C)    declared outside the body of every function.

(D)   declared any where in the C program.

                                                                                                                     

             d.   main ( ) is an example of

 

                   (A)  library function                              (B)  user defined function

                   (C)  header                                          (D)  statement

 

             e.   While incrementing a pointer, its value gets increased by the length of the data type to which it points. This length is called

 

(A)     scale factor                                  (B)  length factor

(C)  pointer factor                                (D)  increment factor


 

             f.    The first digit of a decimal constant must be

 

(A)     a zero                                          (B)  a non zero number

(C)  a negative number                         (D)  an integer

 

             g.   What is the output of the following statement:

                   printf (“%-3d”,12345);

 

(A)     1 2 3                                            (B)  -1 2 3

(C)  1 2 3 4 5                                      (D)  12     

 

             h.   A single character input from the keyboard can be obtained by using the function.

       

(A)    printf ( )                                        (B) scanf ( )

(C) putchar ( )                                     (D) getchar ( )

 

             i.    The function ftell  ( )

 

(A)   reads a character from a file         

(B)   reads an integer from a file

(C) gives the current position in the file

(D) sets the position to the beginning of the file.

 

             j.    If the variables i, j and k are assigned the values 5,3 and 2 respectively, then the expression i = j + ( k + + = 6 ) + 7

 

(A)  gives an error message                  (B)  assigns a value 16 to i

(C)  assigns a value 18 to i                   (D)  assigns a value 19 to i

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

 

  Q.2     a.   Explain the concept of top-down design for a program.                                       (5)

       

             b.   What are compilers and interpreters? List the advantages of an interpreter over a compiler.  Under which situations you will prefer to use interpreter over compiler.                                                   (8)

 

             c.   Give any two characteristics of a good programming language.                            (3)

 

  Q.3     a.   Write a program in C to demonstrate the use of scope resolution operator.          (8)

 

             b.   Write a program in C to find the sum of the first 100 natural numbers

                   Sum=1+2+3+…….100                                                                                     (8)          

 

 

 

 

  Q.4     a.   Write a C program to read a set of numbers from the keyboard and to sort to given array of elements in ascending order using a function.                                                                      (7)

 

             b.   Write a recursive function to calculate the factorial of a positive integer.               (6)

 

             c.   How does an enumstatement differ from a typedef statement?                             (3)

 

  Q.5     a.   Define a structure. How it is different from union?  Write a C program to illustrate a structure.                                                                    (8)

       

             b.   Write a C program to concatenate two strings.                                                   (8)

 

  Q.6     a.   What is a pointer? How it is declared? Write a C program to reverse a string using pointers.                                                                      (2+3+4)

 

             b.   Differentiate between pointers and arrays? Write a C program to display the contents of an array using a pointer arithmetic.                                (2+5)

       

  Q.7     a.   What is a linked list? List different types of linked list.  Write a C program to demonstrate a simple linear linked list.                                            (2+2+6)

                                                     

             b.   Explain the different types of memory allocations in C.                                        (6)

 

  Q.8     a.   Explain the following file functions.

                   (i)   fgetc( )                                          (ii)   ftell

                   (ii)  fgets( )                                           (iv)  rewind( )

                   (v)  fseek                                                                                                           (5)          

 

             b.   Write a program that reads the following information from the keyboard – student_id, student name and total marks and writer to a file.  After taking the information it closes the file and displays the information about the student whose student_id has been entered by the user.                                      (9)                                  

       

             c.   Define macros.                                                                                                   (2)

 

  Q.9     a.   Write a C program that reads two strings str1 and str2 and finds the no of occurrence of smaller strings in large string.                                          (8)

 

             b.   Explain path testing.                                                                                           (6)

 

             c.   Distinguish between malloc( ) and calloc( ).                                                         (2)