C++ program to print the square of the numbers
kw.cpp
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int i, j, n;
    cout<<"How many numbers you want to print ";
    cin>>n;
    cout<<"—————————————————————————————";
    cout<<"\nNumbers |"<<" Squares\n";
    cout<<"—————————————————————————————\n";
    for (int i = 1; i <= n; i++)
    {
        j = i * i;
        cout<<setw(3)<<i<<"     | "<<"  "<<j<<"\n";
    }
    cout<<"—————————————————————————————\n";
    return 0;
}
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out How many numbers you want to print 15 ————————————————————————————— Numbers | Squares ————————————————————————————— 1 | 1 2 | 4 3 | 9 4 | 16 5 | 25 6 | 36 7 | 49 8 | 64 9 | 81 10 | 100 11 | 121 12 | 144 13 | 169 14 | 196 15 | 225 ————————————————————————————— kodingwindow@kw:~$
Advertisement