#include "magic.h"
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
/*

 To create this example, run BC 4.5 make.

 To run the example, run

    magic n

 where n is a small positive integer.

 (c) Copyright Yaron Keren 1995

*/

main(int argc, char **argv) {
  M square, colsum, rowsum;
  int i,j,n;

  if (argc<2) {
    n=10;
  } else
  if (sscanf(argv[1], "%d", &n)!=1) {
    n=10;
  }

  initM();

  magicsum(n, i_o, square, colsum,  rowsum);

  cout<<"Magic square is:"<<endl;
  for (i=1;i<=n;i++) {
    for (j=1;j<=n;j++) {
      cout.width(5);
      cout<<scalar(square, i, j)<<" ";
    }
    cout<<endl;
  }
  cout<<endl;

  cout<<"Coloumn sum is:"<<endl;
  for (i=1;i<=n;i++) {
    cout<<scalar(colsum, i)<<" ";
  }
  cout<<endl<<endl;

  cout<<"Row sum is:"<<endl;
  for (i=1;i<=n;i++) {
    cout<<scalar(rowsum, i)<<" ";
  }
  cout<<endl;

  exitM();

  return 0;
}
