banner

 

#include <stdio.h>
#include <iostream>
using namespace std;

int myarray[5][5] = {};


int main(){
int posx=0,posy=2;
for(int x = 0; x<5; x++){
for(int y = 0; y < 5; y++){
myarray[x][y] = 0;
}
}
for(int i = 1; i<=25; i++){
myarray[posx][posy] = i;
if(posx == 0)
{
if (posy+1<=4)
{posx = 4; posy +=1;}
else
posx=posx+1;

}
else
{

if (posy+1 > 4)
{ posx = posx-1; posy = 0;}
else if (myarray[posx-1][posy+1] != 0)
posx = posx +1;
else { posx = posx-1; posy = posy+1;}
}
}
for(int x = 0; x<5; x++){
for(int y = 0; y < 5; y++){
cout << myarray[x][y]<<" ";

}
cout <<endl;
}

system("pause");

}

 

Output:

MagicSqiuare

Share