Programming for Problem Solving - B.Tech 1st Semester Exam., 2019 (New Course)

2019Semester 3Civil-CAEnd Semester
Bihar Engineering University, Patna
B.Tech 1st Semester Exam., 2019 (New Course)

Programming for Problem Solving

Time: 3 hours Code: 100104 Full Marks: 70

Instructions:

  1. All questions carry equal marks.
  2. There are NINE questions in this paper.
  3. Attempt FIVE questions in all.
  4. Question No. 1 is compulsory.
Q.1 Choose the correct answer from any seven of the following: [14]
  1. Let x be an integer which can take a value of 0 or 1. The statement if (x == 0)x = 1; else x = 0; is equivalent to which one of the following?

    1. x = 1 - x
    2. x = x + 1
    3. x = x * 1
    4. x = 1% x
  2. A program attempts to generate as many permutations as possible of the string, 'abcd' by pushing the characters a, b, c, d in the same order onto a stack, but it may pop off the top character at any time. Which one of the following strings cannot be generated using this program?

    1. abcd
    2. dcba
    3. cabd
    4. cbad
  3. Suppose a C program has floating constant 1.414, what is the best way to convert this 'float' data type?

    1. (float)1.414
    2. Float (1.414)
    3. 1.414f or 1.414F
    4. 1.414 itself of 'float' data type, i.e., nothing else required
  4. What is the output of the following program?
    void main(){
      int a;
      a=1;
      while(a<=1)
        if(a%2)
          printf("%d", a++);
        else
          printf("%d", ++a);
      printf("%d", a+10);
    }

    1. 011
    2. 012
    3. 111
    4. 112
  5. What is the output of this C code?
    #include<stdio.h>
    void main()
    {
      int a = 5 * 3 + 2 - 4;
      printf("%d", a);
    }

    1. 13
    2. 14
    3. 12
    4. 16
  6. What is the output of this C code?
    #include<stdio.h>
    void main()
    {
      int b = 6;
      int c = 7;
      int a = ++b+c--;
      printf("%d", a);
    }

    1. Run-time error
    2. 15
    3. 13
    4. 14
  7. What is the output of this C code?
    #include<stdio.h>
    void foo(int*);
    int main()
    {
      int i = 10;
      foo((&i)++);
    }
    void foo(int* p)
    {
      printf("%d ", *p);
    }

    1. 10
    2. some garbage value
    3. compile-time error
    4. segmentation fault/code crash
  8. User-defined data type can be derived by

    1. struct
    2. enum
    3. typedef
    4. All of the above
  9. As per C language standard, which of the following is/are not keyword(s)? Pick the best statement:
    auto, make, main, sizeof, elseif

    1. make, main
    2. sizeof
    3. auto, make
    4. make, main, elseif
  10. What is the output of this C code (when 1 is entered)?
    #include<stdio.h>
    void main()
    {
      double ch;
      printf ("enter a value between 1 to 2:");
      scanf("%lf", &ch);
      switch (ch)
      {
        case 1:
          printf("1");
          break;
        case 2:
          printf("2");
          break;
      }
    }

    1. Compile-time error
    2. 1
    3. 2
    4. None of the above
Q.2 Solve this question : [14]
  1. What do you mean by pre-processor? Also explain the use of %i format specifier w.r.t, scanf() function.

Q.3 Solve this question : [14]
  1. Write a C program to Perform binary search on a set of given sorted numbers.

Q.4 Solve this question : [14]
  1. Write a C program to find the number of lines in a text file.

Q.5 Solve this question : [14]
  1. Explain pointer arithmetic with the help of suitable diagrams.

Q.6 Solve this question : [14]
  1. Explain the following bitwise operators:
    (a) Bitwise AND
    (b) Bitwise OR
    (c) Bitwise XOR
    (d) Bitwise Left Shift

Q.7 Solve this question : [14]
  1. What do you mean by 'call by reference'? Explain with the help of a function which swaps two numbers.

Q.8 Solve this question : [14]
  1. Write a C program of the following:
    (a) Reverse a string without using strrev().
    (b) Concatenate two strings without using strcat()

Q.9 Solve this question : [14]
  1. Write a 'recursive' C program to print the following:
    (a) GCD of two numbers
    (b) Merge-sort of a set of given numbers