Roll No.
: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
                                 Amrita Vishwa Vidyapeetham
                         B.Tech. Degree Examinations – Nov/Dec. 2014
                                        First Semester
                           CSE100 Computer Programming
                                    (Common to all branches)
Time: Three hours                                                           Maximum: 100 Marks
                                      Answer all questions
Part A                                                                        (10 x 2 = 20 marks)
    1. If variables are declared as int a=3,b=2,c=1,d; What will be the value of „d‟ after
       execution of d=a<b<c-1; Justify your answer.
    2. State the reason why we don‟t use „&‟ before „str‟ in scanf(“%s”,str); statement.
    3. Write the output of the following program snippet. Also tell the use of the code.
       int a[3][3] = {1, 2, 3, 2,1,3, 3,2,1},i;
       for(i=0;i<3;i++)
        printf(“%d”, a[i][i]);
    4. Given char str1[ ]=”Amrita Vishwa Vidyapeetham University”,Dynamically allocate
       memory for another string str2 and copy str1 to str2.
    5. What will be the output of the following program?
       int val;
       static int fun()
       {         return val*val;       }
       main()
       {        val=5;
                printf(“%d\n”,fun());
                val++;
                printf(“%d\n”,fun()); }
    6. State true or false:
       a) A function may be placed either before or after main().
       b) The declarations char name[10]; and char *name; are identical.
       c) A function can have only one return value.
       d) main function can call itself.
    7. The following code is written to compare the two numbers whether they are equal or not.
       However, every time when the user runs the code snippet with different integer values
       finds the same output, says “The two values are not equal”. What is the reason? If the
       code has to be changed which part of the code will be effected?
       main( )                                             scanf(“%d%d”,&i,&j);
       {int i,j;                                           equal(&i,&j);         }
       void equal(int *i,int *j);
       printf(“Enter two numbers\n”);
       void equal(int *i,int *j)                           else
       {if(i==j)                                                   printf(“The two values are
                 printf(“The two values are                not equal\n”); }
       equal\n”);
R                                                                                       Page 1 of 4
8. struct
       {        short s[5];
                union
                {       float f;
                        long lo;
                }x;
         }y;
         Assume that short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. What
         is the memory requirement for the variable y? Explain.
9. Predict the output or mention error if any.
         #define func(x,y) { func(x,y) }
          main()
         {       int a=5,b=6;
                 c=func(a,b);
                 printf(“%d”,c); }
10. Suppose the compiled object program is stored in a file called ELECTION.exe,
              main (int argc, char *argv[ ]) {……}
    Determine the value of argc and non empty elements of argv when the following commands
    are issued to initiate the execution of the program:
           ELECTION candidate‟s with age>17 are “ELIGIBLE FOR VOTING”
Part B                                                                         (6 x 5 = 30 marks)
11. An admission charge for „XYZ‟ theatre varies according to the age of the person. Develop
    an algorithm and draw flowchart to print the ticket charge given the age of the person. The
    charges are as follows: a) Over 55: Rs80.00     b) 21–54: Rs125.00 c) 13–20: Rs100.00
    d) 3–12: Rs75.00          e) Under 3: Free
12. Write C program to count the number of „A‟ votes, „B‟ votes and invalid votes. If the
    character „0‟ is entered, the program should terminate. For all other characters, the loop has
    to be repeated.
13. Write a recursive C function named “revstring” with a pointer to a string as formal
    parameter to display the reverse of the string. Trace the function by specifying the values of
    the variables in each function call, if the input given is “computer”.
14. A C program contains the following declaration:
       static char *color[6]={“red”,”green”,”blue”,”white”,”black”,”yellow”};
    a) What is the meaning of color? b) What is the meaning of (color+2)? c) What is the value
    of *color? d) What is the value of *(color+2)? e) How do color[5] and *(color+5) differ?
R                                                                                      Page 2 of 4
15. Define three bit fields, called a, b, c whose widths are 8 bits, 4 bits, 8 bits, respectively.
    Separate a and b with 2 vacant bits. How will these fields be stored within the computer‟s
    memory? (Assume if it is16-bit memory)
16. Go through the following table and Fill the blanks:
    File Mode             Meaning of Mode                  During Inexistence of file
          r              Open for reading.           If the file does not exist, fopen() returns NULL.
         w                 ---------                              ----------------------
         a                 ---------                              ----------------------
         r+                ---------                              ----------------------
         w+                 ---------                             ----------------------
         a+                ---------                              ----------------------
Part C                                                                         (5 x 10 = 50 marks)
17. a) A and B are two arrays of same size. Get the values for the array elements A from the user.
       Write a program to create the array B, using the elements of array A in such a way that the
       elements of the first column of A are the same as the last column of array B and so
       on.(i.e., B is a mirror image of A) using functions.                                (5 marks)
       The input and output arrays would appear as follows:
                 Array A                 Array B
                 1234                    4321
                 5678                    8765
                 9012                    2109
    b) Read an array p[ ] from the user. Write a program to shift it circularly left by one position.
        Eg: If p[ ] is an array of following 5 elements                                    (5 marks)
                 p[0] = 15, p[1]= 30, p[2] = 28, p[3]= 19 and p[4] = 61
        then after the shift, the array looks like below
                 p[0] = 30 p[1] = 28, p[2] = 19, p[3] = 61, p[4] = 15
18. a) What is printed by the following C program? Show the manipulation of values passed
       to function in steps.                                                         (3 marks)
        int f(int x, int *py, int **ppz){   void main(){
          int y, z;                           int c, *b, **a;
          **ppz += 1;                         c = 4;
          z = **ppz;                          b = &c;
          *py += 2;                           a = &b;
          y = *py;                            printf( "%d", f(c,b,a));
          x += 3;                             getchar();}
          return x + y + z;}
    b) What does the following fragment of C-program print? Validate your answer with reason.
        char c[ ] = "ICPC2014";
        char *p =c;
        printf("%s", p + p[3] - p[1]);                                               (3 marks)
R                                                                                        Page 3 of 4
    b) Explain the working of the given function when the input array contains numbers 1 to 10
        and n is 5. Write the arguments and value returned by each function call. (4 marks)
      int s (int a[ ], int n){ if (n == 1)
                         return a[0];
               else
                         return (a[n-1] + s (a,n-1));}
19. The results of a survey of the households in your township have been made available. Each
    record contains data for one household, which includes a four-digit identification number, the
    annual income for the household, and the number of members of the household. Write a
    program to store the survey results into an array of user defined structure household and
    perform the following analysis: (i) Display the data read for n surveys. (ii) Calculate the
    average household income (iii) Print the details of households having the lowest income
20. a) Point out all the errors in the following code and write the corrected statements. (6 marks)
       struct Student
                {char name[20];
                int age=15;
                float height; }
                main()
                {Student S1; s2={157.5,‟mona‟;20};
                S1.name = "Guru"; S1.age=18; S1.height=160.8;
                If(S1=s2)
                printf("%s %d %f",name,age,height); }
    b) Write a C program to read a float value x. Define a user defined function which takes x as
       argument and evaluates y as follows :                                           (4 marks)
           y=
21. a) Write C Program Delete a specific Line from a Text File                           (7 marks)
    b) Write statements using fseek() to achieve the following.                    (3 marks)
       i) To go backward by 10 bytes from the current position. ii) To go forward by 8 bytes
       from the beginning iii) To go forward by 8 bytes from the end.
                                             *****
R                                                                                       Page 4 of 4