Cpp - Write program to output a complete multiplication table.

Requirements

Write a C++ program that outputs a complete multiplication table.

              ****** MULTIPLICATION TABLE   ****** 

     1    2   3    4   5    6   7    8     9     10 
 1   1    2   3    .       .       .            .           .            . 10 

 2   2    4   6                                  20 

 3   .    .   .                                   . 

 4 
     .    .   .                                   . 

 5   .    .   .                                   . 
 6 

 7 

 8 

 9 

10   10  20   30   .       .       .            .           .            . 100 

Hint

Use nested for loop

Demo

#include <iostream> 
#include <iomanip> 
using namespace std; 
int main() /*from  www  .  ja v  a2  s  .  c om*/
{ 
    int  factor1, factor2; 

    cout << "  ******  MULTIPLICATION TABLE  ******" << endl; 

    //  Outputs the first and second line: 
    cout << "\n\n\n        ";                 // 1. line 
    for( factor2 = 1 ; factor2 <= 10 ; ++factor2 ) 
        cout << setw(5) << factor2; 

    cout << "\n        "                      // 2. line 
          << "-------------------------------------------" 
          << endl; 

     //  Outputs the remaining lines of the table: 

     for( factor1 = 1 ; factor1 <= 10 ; ++factor1 ) 
     { 
         cout << setw(6) << factor1 << " |"; 
         for( factor2 = 1 ; factor2 <= 10 ; ++factor2 ) 
           cout << setw(5) << factor1 * factor2; 
         cout << endl; 
     } 
     cout << "\n\n\n";            // To shift up the table 

     return 0; 
}

Result

Related Exercise