Output-based
Question 1 |
Consider the following C program:
#include <stdio.h>
int main()
{<br
int a = 6; int b = 0;
while(a < 10)
{
a = a / 12 + 1; a += b;
}
printf("%d", a);
return 0;
}
Which one of the following statements is CORRECT?
The program prints 9 as output | |
The program prints 10 as output | |
The program gets stuck in an infinite loop | |
The program prints 6 as output |
Question 2 |
Consider the following C program:
Assume that the input to the program from the command line is 1234 followed by a newline character. Which one of the following statements is CORRECT?
Assume that the input to the program from the command line is 1234 followed by a newline character. Which one of the following statements is CORRECT?The program will not terminate
| |
The program will terminate with no output | |
The program will terminate with 4321 as output | |
The program will terminate with 1234 as output |
Question 3 |
Consider the following C code:
int x = 128, y = 110;
do {
if (x > y)
x = x - y;
else
y = y - x;
} while (x != y);
printf("%d", x);
Which one will be the output?
int x = 128, y = 110;
do {
if (x > y)
x = x - y;
else
y = y - x;
} while (x != y);
printf("%d", x);
Which one will be the output?
18 | |
2 | |
92 | |
74 |
Question 3 Explanation:
The loop terminates when x becomes equal to y. At this point, x=2 and y=2
There are 3 questions to complete.
