Solution for Exercise 11-3

ex1103

#include <stdio.h>

int main()
{
    int c;

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

Notes

* Loops in C can spin in only one direction. While you could craft a tricky loop that changed direction, it's just easier to use two loops, one for each direction.

* The decrement operator appears at Line 9 in the for statement.

* The blank space after %d in both Lines 8 and 10 keeps the output looking clean.