Sunday, March 8, 2015

Multiplication table for a number

Script

#include <iostream>
#include <iomanip>
using namespace std;

main()
{
        int number, i, product;

        cout << "Enter a number: ";
        cin >> number;

        for(i = 1; i <= 20; i++)
        {
                product = number * i;
                cout << number << " * " << i << " = " << product << endl;
        }

        return 0;
}

Execution

Enter a number: 7
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70
7 * 11 = 77
7 * 12 = 84
7 * 13 = 91
7 * 14 = 98
7 * 15 = 105
7 * 16 = 112
7 * 17 = 119
7 * 18 = 126
7 * 19 = 133
7 * 20 = 140

No comments:

Post a Comment