You are on page 1of 5

PQ1.

md 5/7/2022

What is the ouput of below program

#include <stdio.h>
int get(int n) {
if(n <= 1) {
return n;
}
return get(n - 1) + get(n - 2);
}
void solve() {
int ans = get(6);
printf("%d", ans);
}
int main() {
solve();
return 0;
}

Options

1. compilation error
2. -4
3. 0
4. 8 (Correct)

Which of the lines in the following code will result in compilation error?

1. #include<stdio.h>
2. int main(){
3. int 5a =40;
4. float b = 5.9;
5. printf(“%4.3f”,b)
6. return 0;
7. }

Options

1. 2
2. 3 (Correct)
3. 4
4. 5 (Correct)

What is the ouput of below program

1/5
PQ1.md 5/7/2022

#include<stdio.h>
void main()
{
double pi = 3.1415926535;
int a,i;
for(i=-1; i <= 1; i++)
if(a = pi * i/2)
printf("%d ",1);
else printf("%d ", 0);
}

Options

1. 0 0 0
2. 1 1 1
3. 1 0 1 (Correct)
4. Compilation Error

For the question let a=1, b=2, c=3. Then which of the following statements is true?

Options

1. printf("%d", ++a); prints 1.


2. The value of expression (a%2)+(b%2)+(c%2) is 1.
3. Let d=((a==1)?(a=3):(b==2)). The value of d is 3. (Correct)
4. !(a && b) and ((!a) && (!b)) produce different values.

#include <stdio.h>

int main() {
int num;
scanf("%d", &num);

num = num % 2;
switch(num) {
case (0):
printf("EVEN ");
case (1):
printf("ODD ");
break;

default:
printf("NONE");
break;
}

return 0;
}

2/5
PQ1.md 5/7/2022

Which of the following(s) is(are) correct for the program above?

Options

1. Prints "EVEN ODD " on input 10 (Correct)


2. Prints "EVEN ODD NONE" on input 10
3. Prints "ODD " on input 3 (Correct)
4. Prints "ODD NONE" on input 3

Given the C code below, which of the following numbers (as shown in the options below) will be the output
after running the program.

int main(void) {
int loopUntil = 10;

// Loop Begins
while (loopUntil > 0) {

// Cases Begin
if (loopUntil % 4 == 0) {
printf("%d", 77);
} else if (loopUntil % 2 == 0) {
printf("%d", 88);
} else if (loopUntil % 8 == 0) {
printf("%d", 99);
} else if (loopUntil % 10 == 0) {
printf("%d", 55);
} else {
printf("%d", 0);
}
// Cases End

loopUntil = loopUntil - 1;
// Loop Ends
}

// Prints a new line after loop ends.


printf("\n");

return 0;
}

Options

1. 550990770880880
2. 770770770770770
3. 880770880770880
4. 550770880880880

3/5
PQ1.md 5/7/2022

The correct order of operator evaluation for the given expression:

a = b / c << d + ~e % f && g - h || i <= j | k

Options

1. ~ / % + - << <= | && || = (Correct)


2. ~ / % << - + <= | || && =
3. = / % + - ~ << <= | && ||
4. / ~ % + - << <= | && || =

#include<stdio.h>

int main(){
int a = 7;
while(a == 7){
printf("ESC101");
}
}

How many times ESC101 will be printed.

Options

1. ESC101 is printed only once


2. ESC101 is printed an unlimited number of times
3. printf satement is not executed
4. None of the above

Consider the following C program:

#include<stdio.h>

int main () {

int m = 10;
int n, n1;

n = ++m;
n1 = m++;
n--;
--n1;
n = n - n1;

printf ("%d",n);

4/5
PQ1.md 5/7/2022

return 0;

The output of the program is ____

Options

1. 1
2. -1
3. 0 (Correct)
4. 2

Suppose you are given three numbers a,b,c. You want to find the minimum of these 3 numbers. A simple
algorithm would be to first compute the minimum of two numbers (MinTwo). Now compute the minimum of
three numbers (MinThree) by taking the minimum of the third number and MinTwo. It can be easily verified
that MinThree would be the minimum of a,b,c.

You are given the pseudocode for the algorithm described above, fill in the missing blanks B1, B2, B3, B4, B5

1. input a,b,c
2. If a < (B1) , then (B2) = a
3. Else (B3) = (B4)
4. If MinTwo < b , then MinThree = MinTwo
5. Else MinThree = (B5)
6. Print MinThree

Answer

B1 = c
B2 = MinTwo
B3 = MinTwo
B4 = c
B5 = b

5/5

You might also like