In this post, we will write a C++ program to use setw.

C++ program to use setw


C++ program to use setw.

#include<iostream>
#include<conio.h>
#include<iomanip>

int main()
{
    system("cls");

    int i,res;

    for(i=1;i<=10;i++)
    {
        res = i*i;
        std::cout<<i<<std::setw(6)<<res<<std::endl;
    }

    getch();
    return 0;
}



Output

1       1
2       4
3       9
4       16
5       25
6       36
7       49
8       64
9       81
10      100