ProgrammingVery hardGATE CS
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int i, j, k = 0;
for (i = 0, j = 20; i < j; i += 3, j -= 2)
k += j - i;
printf("%d %d %d", i, j, k);
return 0;
}- A. 12 12 50
- B. 9 14 50
- C. 12 12 52
- D. 12 10 50
Correct answer: A. 12 12 50
The pairs (i, j) at the start of each iteration are (0,20), (3,18), (6,16), (9,14), each adding j - i = 20, 15, 10, 5, so k = 50. After the fourth update i = 12 and j = 12, and the test 12 < 12 fails.
More C Programming questions
- What is printed? (sizet is an unsigned type.) c #include <stdio.h> #include <string.h> int main(void) { char s[] = "ab", t[] = "abcd"; if…
- What is printed? c #include <stdio.h> int f(int x) { int r = 0; switch (x) { case 1: r += 1; default: r += 10; case 2: r += 2; break; case…
- What is the exact output? c #include <stdio.h> void p(int n) { if (n <= 0) return; printf("%d", n); p(n - 1); printf("%d", n); p(n - 2); }…
- What is printed? Assume int is 4 bytes and the array is a 2-D array object of automatic storage. c #include <stdio.h> int main(void) { int…
- What is printed? Assume IEEE-754 float (32-bit) and double (64-bit) with no extended-precision evaluation. c #include <stdio.h> int…
- What is printed? c int a[5] = {1, 2}; printf("%d %d %zu", a[1], a[2], sizeof a / sizeof a[0]);