ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[] = {4, 2, 5, 1};
for (int i = 0; i < 3; i++)
printf("%d ", a[i] > a[i + 1] ? a[i] : a[i + 1]);
}- A. 4 5 5
- B. 4 2 5
- C. 5 5 5
- D. 4 5 1
Correct answer: A. 4 5 5
The maximum of each adjacent pair is max(4,2) = 4, max(2,5) = 5 and max(5,1) = 5.
More C Programming questions
- How many pairs (i, j) with i < j have a[i] XOR a[j] equal to 5 for a = {1, 2, 3, 4}? Compute with this program. c #include <stdio.h> int…
- What is printed? c #include <stdio.h> struct N { int v; struct N nx; }; struct N rev(struct N h, struct N prev) { if (!h) return prev…
- What is printed? c #include <stdio.h> int main(void) { unsigned long long r = 1, b = 7; int e = 222; while (e) { if (e & 1) r = r b %…
- What is printed? c #include <stdio.h> int main(void) { unsigned h = 0; for (const char s = "abcdefgh"; s; s++) h = (h << 5) ^ (unsigned…
- What is printed? c #include <stdio.h> int pc(int x) { int c = 0; while (x) { c += x & 1; x >>= 1; } return c; } int cmp(const void a…
- What is printed? c #include <stdio.h> int C(int n) { if (n == 0) return 1; int s = 0; for (int i = 0; i < n; i++) s += C(i) C(n - 1 - i)…