Formatted, aligned output
//set left right
//set precision
#include<iostream.h>
#include<iomanip>
#include<cmath>
int main(int argc, char *argv[])
{
cout<<setw(3)<<"x"<<setw(10)<<"x^2"<<setw(15)<<"sqrt x"<<endl;
for(int i=0; i<10;i++)
{
cout<<resetiosflags(ios::left)<<setw(3)<<setprecision(1)<<i<<setiosflags(ios::right)<<setw(10)<<setiosflags(ios::fixed)<<i*i<<setiosflags(ios::right)<<setw(15)<<setprecision(2)<<sqrt(i)<<endl;
}
return 0;
}
Comments
Post a Comment