# PLZZ HELLP!! I need to edit a Magic Square program!!! HEELPP PLZZ

[b][red]This message was edited by jazzydawg at 2002-7-31 16:7:58[/red][/b][hr]
Hi I have this C++ code for a magic Square (pasted Below) I need to modify this, OR have any code that does the same job(priting a magic square) BUT USING VECTORS. Please help me as i have no clue about vector syntax!
thanx..& herez My code!

/* This program takes in an odd number 'n' input and prints a magic
square of diamensions n x n. */

#include
#include
using namespace std;
const int size = 20;
int square [size][size] = {0};

int main()
{
int num;
do{
cout <<"Please Enter an odd number: ";
cin>> num;
cout << endl;
}

// Constructing magic square.
while(num % 2 == 0 || num < 1 || num > size);
{
int row = num - 1;
int col = num / 2;
for (int i=1; i<=num*num; i++)
{
square[row][col]=i;
if (row == num - 1 && col == num - 1)
row--;
else
if (row < num - 1 && col < num - 1 && square[row+1][col+1] != 0)
row--;
else
{
row = (row + 1) % num;
col = (col + 1) % num;
}
}
}

// Printing The square
for (int row = num - 1; row>= 0; row--)
{
for (int col=0; col<num; col++)
cout << setw(4) <<square[row][col];
cout <<endl;
cout <<endl;
}
return 0;
}

Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!