ProgrammingHard
int c = 0; for (int i = 0; i * i <= 50; i++) c++; printf("%d", c); What is printed?
- A. 8
- B. 7
- C. 9
- D. 50
Correct answer: A. 8
The values 0 to 7 satisfy i * i <= 50, since 7 * 7 = 49 and 8 * 8 = 64. That is 8 values.
More C Programming questions
- int c = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < i; j++) printf("x"), c++; printf("%d", c); What is printed?
- int i = 0, c = 0; while (i i < 50) { c++; i++; } printf("%d", c); What is printed?
- int c = 0; for (int i = 1; i <= 100; i++) if (i % 7 == 0) c++; printf("%d", c); What is printed?
- int cnt = 0; for (int i = 0; i < 10; i += 3) cnt++; printf("%d", cnt); What is printed?
- int i = 0, j = 10, cnt = 0; while (i < j) { i++; j--; cnt++; } printf("%d", cnt); What is printed?
- unsigned int i; for (i = 10; i >= 0; i--) { } What is the behaviour of this loop?