Using variables in the for loop initialization, condition, and altering statements - C++ Statement

C++ examples for Statement:for

Description

Using variables in the for loop initialization, condition, and altering statements

Demo Code

#include <iostream>
#include <iomanip>
using namespace std;
int main()//from w w  w. j av  a 2s .c om
{
   int num, final;
   cout << "Enter the final number for the table: ";
   cin  >> final;
   cout << "NUMBER SQUARE CUBE\n";
   cout << "------ ------ ----\n";
   for (num = 1; num <= final; num++)
      cout << setw(3) << num << setw(8) << num * num << setw(7) << num * num * num << endl;
   return 0;
}

Result


Related Tutorials