🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Matrix Programs in C: all 10 questions

Quiz: Matrix Programs in C · Question 5 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
int main(void) {
    int m[3][3] = {{4, 1, 2}, {6, 5, 3}, {9, 8, 7}};
    int d1 = 0, d2 = 0;
    for (int i = 0; i < 3; i++) { d1 += m[i][i]; d2 += m[i][2 - i]; }
    printf("%d %d\n", d1, d2);
    return 0;
}
  1. A.15 15
  2. B.16 16
  3. C.16 11
  4. D.13 16
Answer & explanation

Correct answer: 16 16

Main diagonal 4 + 5 + 7 = 16; secondary diagonal 2 + 5 + 9 = 16.

Can you get the rest right without peeking?

Take the timed Quiz: Matrix Programs in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →