Control the field width with setw to leave gap between two values - C++ Language Basics

C++ examples for Language Basics:Console

Description

Control the field width with setw to leave gap between two values

Demo Code

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()/*from w ww  .  ja  v a  2 s .com*/
{
   const int MAXCOUNT = 5;
   int count;
   cout << "NUMBER  SQUARE ROOT\n";
   cout << "------    -----------\n";
   cout << setiosflags(ios::showpoint);
   for (count = 1; count <= MAXCOUNT; count++)
      cout << setw(4) << count << setw(15) << sqrt(double(count)) << endl;
   return 0;
}

Result


Related Tutorials