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

 To create this example, see makefile.bcc
 for Borland C++ or makefile.gcc for GNU C++.

 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(cin,cout,cerr);

  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<<square.r(i,j)<<" ";
    }
    cout<<endl;
  }
  cout<<endl;

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

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

  exitM();

  return 0;
}
