Program: DIV and MOD tables


Examples of quotient division and modulo (MOD and DIV) using loops to generate repeating sequences.

C++ program to compile and run using on the Raspberry Pi, Apple Mac or Linux PC. Alternatively you can paste the code into repl.it

Code below...


// MOD and DIV - Phil Gardner

#include <iostream>

using namespace std;

int main()
{
    int quotient, remainder;

    for ( int divideBy = 1;  divideBy <= 10;  divideBy++ )
    {
        cout << endl << endl << "Dividing each number by " << divideBy << "..." << endl << endl;

        for ( int num = 1;  num <= 20;  num++ )
        {

            quotient = num / divideBy;

            remainder = num % divideBy;

            cout << '\t' << num << " DIV " << divideBy << " is " << quotient;

            cout << '\t' << num << " MOD " << divideBy << " is " << remainder;

            cout << endl;

        } // end of inner for (num)

    } // end of outer for loop (divideBy)

}