Solution for Exercise 11-8

ex1108

#include <stdio.h>

#define VALUE 3

int main()
{
    int a;

    printf("Modulo %d:\n",VALUE);
    for(a=0;a<30;a++)
        printf("%d %% %d = %d\n",a,VALUE,a%VALUE);
    return(0);
}

Notes

* The only real change in the code is to Line 3, where the constant value is changed. That has effect beyond Line 3, which is why it's useful to create constants in your programs where applicable.

* The output looks like this:

* It's important that you get the order correct when writing a modulo statement: The larger value comes first. When you put the larger value second you won't get the results you want.