AMIETE – CS/IT (OLD SCHEME)

 

Code: AC05 / AT05                                                Subject: PROGRAMMING & PROBLEM

Flowchart: Alternate Process: 	JUNE 2010                                                                                                            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 the best alternative in the following:                                (210)

                

             a.   What is the output of the following ‘c’ program?

                                    main()

{

                                    extern int i

i=30;

printf(“%d”,sizeof(i));

                                 }

(A)    2                                                 

(B)     4

                   (C)  would vary from compiler to compiler        

                   (D)  error, i undefined

 

             b.   In the following program, find out the error, if any.

 

main()

{

int i = 1;

for(;;)

{

printf(“%d”,i++);

if (i>10)

break;

}}

 

(A)   the condition in the for loop is  must.        

(B)   the two semicolons should be dropped.

                   (C)  the for loop should be replaced by while loop.       

                   (D)  no error.

 

c.       How many times the following c program would print ‘hello’?

 

main()

{

printf( “hello”);

main();

                   }


(A)  infinite number of times             (B)  till the stack does not overflow

                   (C)  34567 times                                (D) Error

       

d.      In a ‘c’ program , #define is defined

(A)    before main                                

(B)    after main

(C) anywhere, but starting on a new line                                                                      

(D) none of the above

 

e.    Which of the following operators in ‘c’ language takes only integer operands?

(A)    +                                                  (B) *

(C)  %                                                (D) /

 

             f.    The value of an automatic variable that is declared but not initialized will be

 

(A)    0                                                 (B)  –1

(C)  garbage                                      (D)  NULL          

 

             g.   Recursive procedures are executed in a

 

(A)  last in first out order                  (B) first in first out order

(C)  parallel order                              (D) all of the above

 

h.   If the address of the 8th element in a linked list of integers is 1022, then the address of 9th element is

 

(A)    1024                                            (B)  1026  

 (C) 1023                                            (D) don’t know

 

             i.    When an array name is passed to a function? The function   

                   (A) accesses exactly the same array with the same name as the calling           program

                   (B)  accesses the copy of the array passed by the program

(C)  refers to the array using the same name as that used by the calling   program       

(D)  none of the above

 

             j.    printf(“ab”,“dc”,“ef”);print

            

                   (A)  ab                                                (B)  ef

(C)  abdcef                                         (D)  abdcef, followed by garbage

 

 

Answer any FIVE Questions out of EIGHT Questions.

Each question carries 16 marks.

 

 

  Q.2     a.   What do you mean by top down design?  What are its advantages?              (8)          

       

             b.   What do you mean by complexity of an algorithm? Explain the best case, average case and worst case results while analyzing an algorithm.                                                               (8)

 

  Q.3     a.   Write a program to evaluate the power series

                   ex=1+x+x2/2!+x3/3!+---------+xn/n!,   0<x<1                                                   (8)          

 

b.      Assuming the variable string contains the value “we are Indians”. Determine what outputs of the following program statement will be

(i)   printf(“%25.10s”,string);

(ii)  printf(“%s”,string[0]);

(iii) printf(“%c\n”,string[10]-5);

(iv) printf(“%c\n”,string[10]+5);                                                                      (8)

 

  Q.4     a.   Write a program that fills a five by five matrix as follows:

                   (i)    upper left triangle with +1’s

                   (ii)   lower right triangle with -1’s

                   (iii)  diagonals with 0’s.                                                                                   (8)

            

             b.    What is recursion? Write a recursive program to print a Fibonacci series.     (8)

 

  Q.5     a.   Describe the two ways of passing parameters to functions. When do you prefer to use each of them?                                                                                                                         (8)

 

             b.   Define a structure data type named date containing three integer members day, month and year. Develop an interactive program to perform the following tasks:

                   (i)   To read data into structure members by a function.

                   (ii)  To validate the date entered by another function.

                   (iii) To print the date in the format May 23, 2009 by the third function.        (8)

 

  Q.6     a.   Write a program to insert an element at a given position and delete an element from a given position in an array.                                             (8)

 

             b.   Distinguish between the following

                   (i)   actual and formal parameter

                   (ii)  global and local parameter

                   (iii) automatic and static variables

                   (iv) scope and visibility of variables                                                                 (8)

 

  Q.7     a.   Write a function using pointer s to exchange the values stored in two locations in the memory.                                                                      (8)

 

            b.   What is a pointer and how it is initialised? How does pointer help in Dynamic memory Allocation?                                                              (8)

 

  Q.8     a.   Write a program to insert an item in a sorted linked list.                                 (8)

 

             b.   Explain the following functions with a suitable example:                               (8)

 

                   (i)    fprintf()                                       (ii)   ftell()

                   (iii)  rewind()                                      (iv)  ferror()

       

  Q.9     a.   Explain the role of preprocessor. When does a program use #include directive? In #include directives, some file names are enclosed in angle brackets while others are enclosed in double quotation marks. Why?                                                  (8)

 

b.   (i)   Write a nested macro that gives the minimum of three values.

                                                                 (ii)  Distinguish the run time errors and latent errors.       (8)