Professional Documents
Culture Documents
md 5/7/2022
#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)
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
#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
Options
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
}
return 0;
}
Options
1. 550990770880880
2. 770770770770770
3. 880770880770880
4. 550770880880880
3/5
PQ1.md 5/7/2022
Options
#include<stdio.h>
int main(){
int a = 7;
while(a == 7){
printf("ESC101");
}
}
Options
#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;
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