// powertbl.cpp

#include <iostream>
#include <iomanip>

using namespace std;

unsigned long int power (int,int);
void clear_screen ();


int main() {

  int i, j, x, n;

  clear_screen();
  cout << "POWER TABLE" << endl;
  cout << "Will make table of powers of integers from 1 to X, raised to"
					" from 1 to N" << endl;
  cout << "Enter X: ";
  cin >> x;
  cout << "Enter N: ";
  cin >> n;
  clear_screen();

  for (j=1; j<=n; j++)       //column headings
    cout << setw(10) << j;
  cout << endl;
  for (j=1; j<=n; j++)       //"underline" the column headings
    cout << "  --------";
  cout << endl;

  //generate and output table of data
  for (i=1; i<=x; i++) {       //each row
    for (j=1; j<=n; j++)           //each column (of the Ith row)
      cout << setw(10) << power(i,j);
    cout << endl;
  }
}


//****************************************************************
// Compute integer powers.  First arg raised to second arg.

unsigned long int power (int x, int n) {

  int i;
  unsigned long int p;

  p = 1;
  for (i=1; i<=n; i++)
    p = p * x;

  return p;
}


//*******************************************************************
void clear_screen () {

  int i;
  for (i=1; i<25; i++)
    cout << endl;
}


/*

POWER TABLE
Will make table of powers of integers from 1 to X, raised to from 1 to N
Enter X: 10
Enter N: 7



         1         2         3         4         5         6         7
  --------  --------  --------  --------  --------  --------  --------
         1         1         1         1         1         1         1
         2         4         8        16        32        64       128
         3         9        27        81       243       729      2187
         4        16        64       256      1024      4096     16384
         5        25       125       625      3125     15625     78125
         6        36       216      1296      7776     46656    279936
         7        49       343      2401     16807    117649    823543
         8        64       512      4096     32768    262144   2097152
         9        81       729      6561     59049    531441   4782969
        10       100      1000     10000    100000   1000000  10000000
 */
