ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int c = 0;
for (int i = 1; i <= 10; i++)
for (int j = i; i * j <= 10; j++) c++;
printf("%d", c);- A. 15
- B. 27
- C. 14
- D. 10
Correct answer: A. 15
c counts pairs i ≤ j with i·j ≤ 10. For i = 1, j runs 1 to 10 (10 pairs); for i = 2, j = 2 to 5 (4); for i = 3, only j = 3 (1); from i = 4, i·i already exceeds 10. Total 15. '27' counts ordered pairs.
More C Programming questions
- What does z("abcdef") print? c void z(const char s) { if (!s) return; putchar(s); z(s + 2); if (s[1]) putchar(s[1]); }
- Does this function compile, and what does it do? c struct S { int p; }; void f(const struct S s) { s->p = 5; }
- On a two's-complement machine, what is printed? c int x = 5; printf("%d %d", -~x, ~-x);
- What is printed? c const char s = "ab cd"; printf("%zu", strlen(s));
- On an LP64 system (32-bit int, 64-bit long), what is printed? c printf("%zu %zu", sizeof(2147483647), sizeof(2147483648));
- What is printed? c printf("%d %d", '0', '0');