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

2018Semester 2Civil-CAEnd Semester
Bihar Engineering University, Patna
B.Tech 1st Semester Exam., 2018 (New)

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 (any seven): [14]
  1. Which of these, best describes an array?

    1. A data structure that shows a hierarchical behaviour
    2. Container of objects of similar types
    3. Container of objects of mixed types
    4. All of the above
  2. How do you initialize an array in C?

    1. int arr[3] = (1,2,3);
    2. int arr(3) = {1,2,3};
    3. int arr[3] = {1,2,3};
    4. int arr(3) = (1,2,3);
  3. When does the segmentation fault occur?

    1. Compile-time
    2. Run-time
    3. Both of the above
    4. None of the above
  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 the following code?
    void main()
    {
      int i;
      i=0;
      if(i=15,10,5)
        printf("Programming %d",i);
      else
        printf("Skills %d",i);
      getch();
    }

    1. Skills 15
    2. Programming 5
    3. Programming 15
    4. Skills 5
  6. What will be printed as the result of the operation below?
    main()
    {
      char s1[]="Cisco";
      char s2[]="systems";
      printf ("%s", s1);
    }

    1. System
    2. error
    3. Cisco
    4. Compilation fail
  7. Process of inserting an element in stack is called

    1. create
    2. push
    3. evaluation
    4. Pop
  8. Consider the following segment of C-code:
    int j, n;
    j=1;
    while (j<=n)
      j=j*2;
    The number of comparisons made in the execution of the loop for any n>0 is: (Base of log is 2 in all options)

    1. CEIL(log n)
    2. CEIL(log n)+2
    3. FLOOR(log n)+2
    4. n
  9. The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is

    1. 100
    2. 200
    3. 150
    4. 148
  10. What is the output of following program?
    #include <stdio.h>
    int main()
    {
      int a=1;
      int b=1;
      int c=a || --b;
      int d=a-- && --b;
      printf("a=%d, b=%d, c=%d, d=%d", a, b, c, d);
      return 0;
    }

    1. a = 0, b = 1, c = 1, d = 0
    2. a = 0, b = 0, c = 1, d = 0
    3. a = 1, b = 1, c = 1, d = 1
    4. a = 0, b = 0, c = 0, d = 0
Q.2 Solve this question : [14]
  1. How array and pointers are related? Explain with the help of suitable diagrams.

Q.3 Solve both questions : [7+7=14]
  1. Write a C program to count the number lines input by the user.

  2. Explain the difference between call by reference and call by value with the help of a suitable example.

Q.4 Solve this question : [14]
  1. With the help of an example, differentiate between static and dynamic memory allocations.

Q.5 Solve this question : [14]
  1. What are library functions and their users in C language? Can we write our own functions and include them in C library?

Q.6 Solve both questions : [7+7=14]
  1. Write a "recursive" C program to print—
    (a) Fibonacci series;
    (b) factorial of a given number.

Q.7 Solve this question : [14]
  1. Write the differences between structure and union. Compare them with the help of an example.

Q.8 Solve this question : [14]
  1. Write a C program to convert an infix expression into postfix expression. In particular, an infix expression: \((1-2)*(4+5)\) will have postfix expression: \(12-45+*\).

Q.9 Solve this question : [14]
  1. Write a C program to illustrate reading of data from a file.