Solution for Exercise 9-11

ex0911

#include <stdio.h>

int main()
{
    int alpha,code;

    for(alpha='A';alpha<='G';alpha=alpha+1)
    {
        for(code=1;code<=7;code=code+1)
        {
            printf("%c%d\t",alpha,code);
        }
        putchar('\n');      /* end a line of text */
    }
    return(0);
}

Output

A1    A2    A3    A4    A5    A6    A7
B1    B2    B3    B4    B5    B6    B7
C1    C2    C3    C4    C5    C6    C7
D1    D2    D3    D4    D5    D6    D7
E1    E2    E3    E4    E5    E6    E7
F1    F2    F3    F4    F5    F6    F7
G1    G2    G3    G4    G5    G6    G7

Notes

* Think of the outer loop (alpha) as rows. The inner loop (code) is columns.

* Another way to think of a nested loop is like a clock: The outer loop ticks once, like an hour. Then the inner, "nested" loop ticks off it's full count, like minutes. In my solution (above), the outer loop ticks off 'A' first. Then the inner loop ticks from 1 through 7. Next, the outer loop ticks off 'B' and the inner loop repeats.