Page 1 :
1) What will be the value of s if n=127?, Read n, i=0,s=0, Function Sample(int n), while(n>0), r=n%l0, p=8^i, s=s+p*r, i++, n=n/10, End While, Return s;, End Function, a) 27, b) 187, c) 87, d) 120, 2) What will be the value of s if N=20?, Read N, Function sample(N), s = 0, f = 1, i=1;, Do Until i <= N, f = f * i;, s = s +(i / f);, i=i+1, End Do, return(s);, End Function, a) 666667, b) 718282, c) 708333, d) 716667, 3) What will be the output if limit = 6?, Read limit, n1 = 0, n2= 1, n3=1, count = 1;, while count <= limit, count=count+1, print n3, n3 = n1 + n2, n1 = n2, n2 = n3, End While, a) 1235813, b) 12358
Page 2 :
c) 123581321, d) 12358132, 4) What will be the value of even_counter if number = 2630?, Read number, Function divisible(number), even_counter = 0, num_remainder = number;, while (num_remainder), digit = num_remainder % 10;, if digit != 0 AND number % digit == 0, even_counter= even_counter+1, End If, num_remainder= num_remainder / 10;, End While, return even_counter;, a) 3, b) 4, c) 2, d) 1, 5) What will be the value of t if a = 56 , b = 876?, Read a,b, Function mul(a, b), t=0, while (b != 0), t=t+a, b=b-1, End While, return t;, End Function, a) 490563, b) 49056, c) 490561, d) None of the mentioned, 6) Code to sort given array in ascending order:, Read size, Read a[1],a[2],…a[size], i=0, While(i<size), j=i+1, While(j<size), If a[i] < a[j] then, t= a[i];, a[i] = a[j];, a[j] = t;
Page 3 :
End If, j=j+1, End While, i=i+1, End While, i=0, While (i<size), print a[i], i=i+1, End While, wrong statement?, a) Line 4, b) Line 6, c) Line 7, d) No Error, 7) What is the time complexity of searching for an element in a circular linked list?, a) O(n), b) O(nlogn), c) O(1), d) None of the mentioned, 8) In the worst case, the number of comparisons needed to search a singly linked list of length n for a given, element is, a) log 2 n, b) n/2, c) log 2 n – 1, d) n, 9) Which of the following will give the best performance?, a) O(n), b) O(n!), c) O(n log n), d) O(n^C), 10) How many times the following loop be executed?, {, …, ch = ‘b’;, while(ch >= ‘a’ && ch <= ‘z’), ch++;, }, a) 0, b) 25, c) 26, d) 1, 11) Consider the following piece of code. What will be the space required for this code?
Page 4 :
int sum(int A[], int n), {, int sum = 0, i;, for(i = 0; i < n; i++), sum = sum + A[i];, return sum;, }, // sizeof(int) = 2 bytes, a) 2n + 8, b) 2n + 4, c) 2n + 2, d) 2n, 12) What will be the output of the following pseudo code?, For input a=8 & b=9., Function(input a,input b), If(a<b), return function(b,a), elseif(b!=0), return (a+function(a,b-1)), else, return 0, a) 56, b) 88, c) 72, d) 65, 13) What will be the output of the following pseudo code?, Input m=9,n=6, m=m+1, N=n-1, m=m+n, if (m>n), print m, else, print n, a) 6, b) 5, c) 10, d) 15, 14) What will be the output of the following pseudo code?, Input f=6,g=9 and set sum=0, Integer n, if(g>f), for(n=f;n<g;n=n+1)
Page 5 :
sum=sum+n, End for loop, else, print error message, print sum, a) 21, b) 15, c) 9, d) 6, 15) Consider a hash table with 9 slots. The hash function is h(k) = k mod 9. The collisions are resolved by, chaining. The following 9 keys are inserted in the order: 5, 28, 19, 15, 20, 33, 12, 17, 10. The maximum,, minimum, and average chain lengths in the hash table, respectively, are, a) 3, 0, and 1, b) 3, 3, and 3, c) 4, 0, and 1, d) 3, 0, and 2, 16) You have an array of n elements. Suppose you implement a quick sort by always choosing the central, element of the array as the pivot. Then the tightest upper bound for the worst case performance is:, a) O(n2), b) O(nLogn), c) T(nLogn), d) O(n3), 17) Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time on, Depth First Search of G? Assume that the graph is represented using adjacency matrix., a) O(n), b) O(m+n), c) O(n2), d) O(mn), 18) Let P be a Quick Sort Program to sort numbers in ascending order using the first element as a pivot. Let t1, and t2 be the number of comparisons made by P for the inputs {1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively., Which one of the following holds?, a) t1 = 5, b) t1 < t2, c) t1 > t2, d) t1 = t2, 19) What does the following piece of code do?, public void func(Tree root), {, func(root.left());, func(root.right());, System.out.println(root.data());, }
Page 6 :
a) Preorder traversal, b) Inorder traversal, c) Postorder traversal, d) Level order traversal, 20) How will you find the minimum element in a binary search tree?, a) public void min(Tree root), {, while(root.left() != null), {, root = root.left();, }, System.out.println(root.data());, }, b) public void min(Tree root), {, while(root != null), {, root = root.left();, }, System.out.println(root.data());, }, c) public void min(Tree root), {, while(root.right() != null), {, root = root.right();, }, System.out.println(root.data());, }, d) public void min(Tree root), {, while(root != null), {, root = root.right();, }, System.out.println(root.data());, }, 21.In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will, str contain?, A. "I am a boy\r\n\0", B. "I am a boy\r\0", C. "I am a boy\n\0", D. "I am a boy"
Page 7 :
22.What is the purpose of "rb" in fopen() function used below in the code?, FILE *fp;, fp = fopen("source.txt", "rb");, A. open "source.txt" in binary mode for reading, B. open "source.txt" in binary mode for reading and writing, C. Create a new file "source.txt" for reading and writing, D. None of above, 23. What does fp point to in the program ?, #include<stdio.h>, int main(), {, FILE *fp;, fp=fopen("trial", "r");, return 0;, }, A. The first character in the file, B. A structure which contains a char pointer which points to the first character of a file., C. The name of the file., D. The last character in the file., 24. Which of the following operations can be performed on the file "NOTES.TXT" using the below code?, FILE *fp;, fp = fopen("NOTES.TXT", "r+");, A. Reading, B. Writing, C. Appending, D. Read and Write, 25. To print out a and b given below, which of the following printf() statement will you use?, #include<stdio.h>, float a=3.14;, double b=3.14;, A. printf("%f %lf", a, b);, B. printf("%Lf %f", a, b);, C. printf("%Lf %Lf", a, b);, D. printf("%f %Lf", a, b);, 26. Which files will get closed through the fclose() in the following program?, #include<stdio.h>, int main(), {, FILE *fs, *ft, *fp;
Page 9 :
29. Out of fgets() and gets() which function is safe to use?, A. gets(), B. fgets(), 30. Consider the following program and what will be content of t?, #include<stdio.h>, int main(), {, FILE *fp;, int t;, fp = fopen("DUMMY.C", "w");, t = fileno(fp);, printf("%d\n", t);, return 0;, }, A. size of "DUMMY.C" file, B. The handle associated with "DUMMY.C" file, C. Garbage value, D. Error in fileno(), 31. What will be the content of 'file.c' after executing the following program?, #include<stdio.h>, int main(), {, FILE *fp1, *fp2;, fp1=fopen("file.c", "w");, fp2=fopen("file.c", "w");, fputc('A', fp1);, fputc('B', fp2);, fclose(fp1);, fclose(fp2);, return 0;, }, A. B, B. A, B, C. B, B, D. Error in opening file 'file1.c', 32. What will be the output of the program ?, #include<stdio.h>
Page 11 :
#include<stdio.h>, int main(), {, float a=3.15529;, printf("%2.1f\n", a);, return 0;, }, A. 3.00, B. 3.15, C. 3.2, D. 3, 36. What will be the output of the program ?, #include<stdio.h>, int main(), {, printf("%c\n", ~('C'*-1));, return 0;, }, A. A, B. B, C. C, D. D, 37. What will be the output of the program ?, #include<stdio.h>, int main(), {, FILE *fp;, unsigned char ch;, /* file 'abc.c' contains "This is India " */, fp=fopen("abc.c", "r");, if(fp == NULL), {, printf("Unable to open file");, exit(1);, }, while((ch=getc(fp)) != EOF), printf("%c", ch);, fclose(fp);, printf("\n", ch);, return 0;, }, A. This is India
Page 12 :
B. This is, C. Infinite loop, D. Error, 38. What will be the output of the program ?, #include<stdio.h>, int main(), {, char *p;, p="%d\n";, p++;, p++;, printf(p-2, 23);, return 0;, }, A. 21, B. 23, C. Error, D. No output, 39. What will be the output of the program ?, #include<stdio.h>, int main(), {, FILE *ptr;, char i;, ptr = fopen("myfile.c", "r");, while((i=fgetc(ptr))!=NULL), printf("%c", i);, return 0;, }, A. Print the contents of file "myfile.c", B. Print the contents of file "myfile.c" upto NULL character, C. Infinite loop, D. Error in program, 40. What will be the output of the program ?, #include<stdio.h>, int main(), {, printf("%%%%\n");, return 0;, }
Page 13 :
A. %%%%%, B. %%, C. No output, D. Error