Solution for Exercise 9-7

ex0907

#include <stdio.h>

int main()
{
    int backwards;

    for(backwards=25;backwards>=0;backwards=backwards-1)
    {
        printf("%d\n",backwards);
    }
    return(0);
}

Output

25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0

Notes

* Line 7 is the one to get correct, regardless of whether you use the variable name backwards or not.

* You could have specified backwards>-1 as the second condition in the for statement. As long as zero is the final value output, the loop is correct.