ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
int main(void) {
int n = 6;
int result = 1;
for (int i = n; i > 1; i--) result *= i;
printf("%d", result);
}- A. 6
- B. 0
- C. 720
- D. 120
Correct answer: C. 720
This computes 6! by multiplying 6*5*4*3*2 (stopping once i reaches 1, since the loop condition is i>1): 720.
More C Programming questions
- What is printed? c int main(void) { int x = 5, y = 5; if (x = y) printf("true:%d", x); else printf("false:%d", x); }
- What is printed? c int main(void) { int a = 2, b = 3; int result = a++ b-- + --a + ++b; printf("%d %d %d", a, b, result); }
- What is printed? c int main(void) { int n = 4; int triangle = n (n + 1) / 2; printf("%d", triangle); }
- What is printed? c int main(void) { int x = 15; int y = 4; printf("%d %d %d", x / y, x % y, (x / y) y + (x % y)); }
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…