Skip to the task
Layout
Back to classic view

You are looking ahead. Your place is still task 1: Arrays.

CHECKTask 23 of 28 · step 9: Drills: check yourselfColumn by column
Column by column in practice/04/

What do these nested loops print?

Details & hint
int m[2][3] = {{1, 2, 3}, {4, 5, 6}};
for (int c = 0; c < 3; c++) {
    for (int r = 0; r < 2; r++) {
        printf("%d ", m[r][c]);
    }
}

Stuck? 1 4 2 5 3 6: the outer loop goes over the columns, so the array is printed column by column.

practice 04 main.c Code Diff
UNCHANGED This step does not change this file.
#include <stdio.h>
#include "input.h"
int main(void) {
int grade = read_int("Grade (0 - stop): ");
int sum = 0;
int count = 0;
while (grade != 0) {
sum += grade;
count++;
grade = read_int("Grade (0 - stop): ");
}
if (count > 0) {
printf("Average: %.2f\n", (double)sum / count);
} else {
printf("No grades.\n");
}
return 0;
}