/*
 * pow_tab.c
 * This program prints out the table of powers.
 */

#include <stdio.h>

#define MAX_BASE  5
#define MAX_POWER 8

int main ()
{
  int       tab[MAX_BASE + 1][MAX_POWER + 1];
  int       base, power;

  /* Compute the table of powers. */
  for (base = 1; base <= MAX_BASE; base++)
  {
    /* Since x to the power is 0 is always 1: */
    tab[base][0] = 1;

    /* Compute the rest of the row, using the equality:
     *
     *    n    n-1
     *   x  = x    * x
     */
    for (power = 1; power <= MAX_POWER; power++)
      tab[base][power] = base * tab[base][power - 1];
  }

  /* Print the table. */
  for (base = 1; base <= MAX_BASE; base++)
  {
    for (power = 1; power <= MAX_POWER; power++)
      /* Notice we allow 7 digits to get a neat output. */
      printf ("%7d ", tab[base][power]);

    printf ("\n");
  }

  return (0);
}

