U E D R , A S I H C RSS

마방진/김아영

~cpp 
#include <iostream.h>

int main()
{
	int a[5][5]={{0, },};
	int x, y ;

	a[0][2]=1;
	
	x=2;
	y=0;

	for(int count=2;count<26;count++)
	{
			x--;
			y--;
			
		if(y==-1)
			y=4;

		if(x==-1)
			x=4;
	
		if(a[y][x]!=0)
		{	
			y+=2;
			x++;
		}

		if(y>4)
			y=1;

		if(x>4)
			x=0;

		a[y][x]=count;
	}

	for(int i=0;i<5;i++)
	{
		for(int j=0;j<5;j++)
			cout<<a[i][j]<<"\t ";
		cout<<endl;
	}

	return 0;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:24
Processing time 0.0093 sec