Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

9/2/2019 CU Exams

CSE_CS103_ST1_SETB_2019
Test Summary
No. of Sections: 2
No. of Questions: 12
Total Duration: 90 min

Section 1 - MCQ

Section Summary
No. of Questions: 10
Duration: 30 min

Additional Instructions:
None

Q1. Which header le should be included to use functions like malloc() and calloc()?

memory.h

stdlib.h

string.h

dos.h

Q2. What will be the output of the program?


#include<stdio.h>
int main()
{
   int a = 25;
   int *ptr = NULL;
   printf("%d", *ptr);
   return 0;
}

10

Garbage Value

No Output

Syntax Error

Q3. What will be the output of the following code?


#include<stdio.h>
int cnt=0;
void F(int n)
{
    if(n == 0)
    return;
    cnt++;
https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 1/11
9/2/2019     F(n/10); CU Exams

}
int main()
{
    F(123456789);
    printf("%d",cnt);
    return 0;
}

123456789

10

Q4. What will be the output of below program?


              #include<stdio.h>
              int main( )
              {
              char *p;
              p="#k\n";
               p=p+1;
               printf("%c", *p);
              return 0;
              }

No output

Q5. What will be the output of below program?


              #include<stdio.h>
              int f( )
              {
              return (printf("GandhiBlock"));
              }
              int main( )
              {
              int x=f();
             printf("%d", x);
              return 0;
              }

GandhiBlock

GandhiBlock11

GandhiBlock10

No output

https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 2/11
9/2/2019 CU Exams
Q6. Will the given function results in memory leak? 
int* func1()
{
  int *p;
  p = (int*)malloc(4);
  return p;
}

yes

no

unde ned 

syntax error

Q7. Which of the below code snippets performs bubble sort to sort the elements in ascending order?

void bubbleSort(int array[], int n)


{
 int i, j, temp;
 for (i = 0; i < n-1; i++)    
  for (j = 0; j < n-1; j++)
     if (array[j] > array[j+1])
   {
    temp = array[j];
    array[j] = array[j+1];
    array[j+1] = temp;
  }
}

void bubbleSort(int array[], int n)


{
 int i, j, temp;
 for (i = 0; i < n-1; i++)    
  for (j = 0; j < n-1; j++)
     if (array[j] <= array[j+1])
   {
    temp = array[j];
    array[j] = array[j+1];
    array[j+1] = temp;
  }
}

void bubbleSort(int array[], int n)


{
 int i, j, temp;
 for (i = 0; i < n-1; i++)    
  for (j = 0; j < n-1; j++)
     if (array[j+1] > array[j])
   {
    temp = array[j];
    array[j] = array[j+1];
    array[j+1] = temp;
  }
}

None of the above

Q8. What will be the output of the program?


https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 3/11
9/2/2019 #include<stdio.h> CU Exams

#include<stdlib.h>

int main()
{
  int *p;
  p = (int *)malloc(10); /* Assume p has address of 1000 */
  free(p);
  printf("%u", p);
  return 0;
}

10

Garbage value

1000

Random address

Q9. What will be the output of the program?


#include<stdio.h>
int main()
{
  int a = 10;
  void *ptr = &a;
  printf("%d", *(int*)ptr);
  return 0;
}

10

Garbage Value

Syntax Error

Q10. What will be the output of the following C code? 


  #include <stdio.h>
  int main()
  {
    int ary[4] = {1, 2, 3, 4};
    int *p;
    p = ary + 3;
    *p = 5;
    printf("%d\n", ary[3]);
  }

https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 4/11
9/2/2019 CU Exams

Compile time error

Section 2 - CODING

Section Summary
No. of Questions: 2
Duration: 60 min

Additional Instructions:
None

Q1. The following question contains function bubblesort() to sort the array of size 'n' till 'p' number of passes.The main is used scan the
size and p(pass till 
which array need to be sorted).The rst entry will be the 'n' that is the number of elements in aray followed by the value 'p' no of
passes.The function should store 
the array after p passes.

Constraints:
1>=n<=10000
1>=p<=n-1

Sample Input:
8 // no. of elements in array
3 // no. of passes
5
3
1
9
8
2
4
7
Sample Output://resultant array after 3 passes
13245789

Sample Input Sample Output

8 1 3 2 4 5 7 8 9
3
5
3
Time Limit: - ms Memory Limit: - kb Code Size: - kb

Q2. Following is the Fibonacci series. 


0, 1, 1, 2, 3, 5, 8, ...,. 
Explanation:- Except for the rst two terms of the sequence, every other term is the sum of the previous two terms, for example, 8 =
3 + 5 (addition of 3 and 5).
The given code contain function f() which accept 'n' and provide the nth term of Fibonacci Series.The de nition of f() using
recursion. 
Constraints:
1<n<1000

Sample Input:
9
Sample Output:
0
1
1
2
3
5
8
13
21

Sample Input Sample Output


https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 5/11
9/2/2019 CU Exams

9 0
1
1
2
Time Limit: - ms Memory Limit: - kb Code Size: - kb

https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 6/11
9/2/2019 CU Exams

Answer Key & Solution


Section 1 - MCQ
Q1
stdlib.h

Solution

No Solution

Q2
No Output

Solution

No Solution

Q3
9

Solution

No Solution

Q4
k

Solution

No Solution

Q5
GandhiBlock11

Solution

No Solution

Q6
yes

Solution

No Solution

Q7
void bubbleSort(int array[], int n)

 int i, j, temp;

 for (i = 0; i < n-1; i++)    

  for (j = 0; j < n-1; j++)

     if (array[j] > array[j+1])

   {

https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 7/11
9/2/2019 CU Exams
    temp = array[j];

    array[j] = array[j+1];

    array[j+1] = temp;

  }

Solution

No Solution

Q8
1000

Solution

No Solution

Q9
10

Solution

No Solution

Q10
5

Solution

No Solution

Section 2 - CODING
Q1
Test Case

Input Output

5 2 1 6 7 9
2
6
2

Weightage - 20

Input Output

4 33 22 11 44
1
44
33

Weightage - 20

Input Output

8 12 7 22 30 33 67 77 88
5
33
https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 8/11
9/2/2019 CU Exams

Weightage - 20

Input Output

6 4 5 6 7 8 9
5
9
8

Weightage - 20

Input Output

5 9 32 45 66 77
3
77
66
Weightage - 20

Sample Input Sample Output

8 1 3 2 4 5 7 8 9
3
5
3
Solution

Header

#include <stdio.h>
int n,p;

void bubbleSort(int array[], int p){


for(int step=0; step<p; ++step){
for(int i=0; i<n-step-1; ++i){
// To sort in descending order, change > to <.
if (array[i]>array[i+1]){
int temp=array[i];
array[i]=array[i+1];
array[i+1]=temp;
}
}
}
}

Footer

int main()
{
scanf("%d",&n);
scanf("%d",&p);
int data[n];
for(int i=0; i<n; i++)
scanf("%d ", &data[i]);

bubbleSort(data, p);

for(int i=0; i<n; i++)


https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true
for(int i=0; i<n; i++) 9/11
for(int i 0; i<n; i++)
9/2/2019 CU Exams
printf("%d ", data[i]);
return 0;
}

Q2
Test Case

Input Output

5 0
1
1
2

Weightage - 20

Input Output

11 0
1
1
2
Weightage - 20

Input Output

5 0
1
1
2
Weightage - 20

Input Output

7 0
1
1
2
Weightage - 20

Input Output

18 0
1
1
2
Weightage - 20

Sample Input Sample Output

9 0
1
1
2

Solution

Header

https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 10/11
#include<stdio h>
#include<stdio.h>
9/2/2019 CU Exams

int f(int);

int f(int n)
{
if (n == 0 || n == 1)
return n;
else
return (f(n-1) + f(n-2));
}

Footer

int main()
{
int n, i = 0, c;

scanf("%d", &n);

for (c = 1; c <= n; c++)


{
printf("%d\n", f(i));
i++;
}

return 0;
}

https://admin.exam.chitkarauniversity.edu.in/school/test/preview?test_id=b74adb47-a622-4fbc-8a58-3a47fff1f788&branch_id=0c6a9640-ac31-4d4c-9fdd-a4d82966e1a4&isprint=true 11/11

You might also like