ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
int main(void) {
int n = 4;
int triangle = n * (n + 1) / 2;
printf("%d", triangle);
}- A. 16
- B. 6
- C. 10
- D. 8
Correct answer: C. 10
This computes the nth triangular number: 4*5/2 = 20/2 = 10 (equivalently 1+2+3+4=10).
More C Programming questions
- 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…
- 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…
- 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…