Use the while statement to print a table of numbers from 1 to 10 with the numbers' squares and cubes. - C++ Statement

C++ examples for Statement:while

Description

Use the while statement to print a table of numbers from 1 to 10 with the numbers' squares and cubes.

Demo Code

#include <iostream>
#include <iomanip>
using namespace std;
int main()/*from   w  ww.j ava 2s.com*/
{
   int num;
   cout << "NUMBER    SQUARE    CUBE\n" << "------    ------    ----\n";
   num = 1;
   while (num < 11)
   {
      cout << setw(3) << num << "        " << setw(3) << num * num << "      " << setw(4) << num * num * num << endl;
      num++;         // increment num
   }
   return 0;
}

Result


Related Tutorials