Code: AC05/AT05                                                    Subject: PROGRAMMING & PROBLEM

Flowchart: Alternate Process: DECEMBER 2007
                                                                                                              SOLVING THROUGH ‘C’

Time: 3 Hours                                                                                                     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.   Determine which of the following is an invalid character constant.

 

(A)     ‘\a’                                              (B)  ‘T’

                   (C)  ‘\0’                                              (D)  ‘/n’

 

             b.   What is the name of built-in function for finding square roots?

 

                   (A)  square(x)                                      (B)  sqr(x)

                   (C)  sqrt(x)                                          (D)  No built-in function

 

c.       What is the output of following statement?

for(i=1; i<4; i++)

printf(“%d”,(i%2) ? i : 2*i);

 

                   (A)  1   4   3                                        (B)  1   2   3

(C)    2   4   6                                       (D)  2   2   6

       

d. Which of the following statement is true about a function?

 

(A)    An invoking function must pass arguments to the invoked function.                             

(B)    Every function returns a value to the invoker.

(C)    A function may contain more than one return statement.                                             

(D)    Every function must be defined in its own separate file.

            

e.   What is the output of the following program?

       main( )

{

int i=4, z=12;

if(i=5 || z>50)

printf(“hello”);

else

printf(“hye”);

}

 

(A)    hello                                             (B)  hye

(C) syntax error                                   (D) hellohye

 


             f.    For implementing recursive function the data structure used is:

 

(A)    Queue                                         (B)  Stack

(C)  Linked List                                  (D)  Tree  

 

             g.   The size of array int a[5]={1,2} is

                                      

(A)      4                                                 (B)  12                    

(C)  10                                                (D)  6

 

             h.   Which of the following is not an escape sequence?

 

(A)      \n                                                (B) \r

(C)    \’                                                (D) \p

 

             i.    The output of the following statements is

                   char ch[6]={‘e’, ‘n’, ‘d’, ‘\0’, ‘p’};

                   printf(“%s”, ch);

 

                   (A)  endp                                            (B)  end0p

(C)  end                                              (D)  error

 

             j.    How many times the following code prints the string “hello”.

                   for(i=1; i<=1000; i++);

printf(“hello”);

 

(A)  1                                                  (B)  1000

(C)  Zero                                             (D)  Syntax error

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

 

 

  Q.2     a.   What is structured programming?  Explain its advantages.                                   (8)          

       

             b.   What are the essential features of an algorithm? Write an algorithm to obtain H.C.F. of two given positive integers.                                               (8)

 

 

  Q.3     a.   Define the term complexity of an algorithm. How do you calculate the complexity of sorting algorithms? Find the complexity of Insertion sort and Bubble Sort.                                                                (8)       

 

             b.   Given two one-dimensional arrays A and B which are sorted in ascending order. Write a program to merge them into a single sorted array C that contains every item from arrays A and B in ascending order.  (8)       

 

  Q.4     a.   Describe the output that will be generated by the following ‘C’ program.             (4)

 

#include<stdio.h>

main( )

{

int i=0, x=0;

while(i<20)

{ if(i%5 = = 0)

{x + = i;

printf("%d", x);

}

++i;

}

printf(“\nx = %d”, x);

}

                          

b.      Write a complete program to create a singly linked list. Write functions to do the following operations

(i)  Count the number of nodes

(ii)  Add a new node at the end

(iii) Reverse the list.                                                                                          (10)

 

             c.    Why ‘&’ operator is not used with array names in a scanf statement?                 (2)

       

 

  Q.5     a.   What is recursion? Write a recursive program to reverse a string.                        (8)

                                                                                                                                                   

             b.   Distinguish between the following:

                   (i)   Automatic and static variables

                   (ii)  Global and local variables.                                                                           (8)

 

  Q.6     a.   What would be the output of the program given below?

typedef struct soldier

{

char *name;

char *rank;

int serial_number;

} SOLDIER;

SOLDIER soldier1, soldier2, soldier3, *ptr;

ptr = &soldier3;

soldier3.name = “Anand Mohanti”;

printf(“\n%s”, (*ptr).name);

printf(“\n%c”, *ptr->name);

printf(“\n%c”, *soldier3.name);

printf(“\n%c”, *(ptr-> name + 4));

                                                                                                                                            (6)

 

             b.   Define a structure to store the following information about an employee

                   Name, Sex(male, female), Marital_status(single, married, divorced or widowed), age.(using bit fields)                                                                    (4)

 

             c.   How is multidimensional arrays defined in terms of an array of pointer? What does each pointer represent?                                                            (6)

 

  Q.7     a.   Write a program to implement the stack using linked list.                                     (8)

 

             b.   Explain the following functions with the help of examples:

                   (i)  malloc( )           (ii) calloc( )           (iii) realloc( )                                            (8)

       

  Q.8     a.   A file of employees contains data (eno, name and salary) for each employee of a company. Write a program to do the following:

(i)                  create the file

(ii)                insertion in a file

(iii)               deletion from a file

(iv)              modification in a file                                                                              (12)

                  

             b.   What is insertion sort? Write a program to sort the given list of integers using insertion sort.             (4)

 

  Q.9     a.   Define a macro. Write a nested macro that gives the minimum of three values.                     (5)

 

             b.   Write a program to check whether a box is cube, rectangle or semi-rectangle. Prepare a test procedure to test this program.                                 (5)

 

c.       A program has been compiled and linked successfully. When you run this program you face one or more of he following situations

 

                   (i)   Program executed, but no output

                   (ii)  It produces incorrect answers

                   (iii) It does not stop running.

            

                   What are the possible causes in each case and what steps would you take to correct them?                                                                       (6)