Solution for Exercise 9-21

ex0921

#include <stdio.h>

int main()
{
    int a;
    char c;

    for( a=1,c='Z'; a<5; a=a+1,c=c-1 )
        printf("%d%c\n",a,c);
    return(0);
}

Output

1Z
2Y
3X
4W

Notes

* It's common to see the first part or the last part of a for loop's statement double up as shown in this code. Rare is it when both are doubled.

* Remember, commas can separate multiple expressions, but both semicolons are required in a for loop's parentheses.