U E D R , A S I H C RSS

Magic Square/성재

~cpp 
마방....음...이름이..기억이..-_-;;
허접 소스입니다만..일단은 올려둡니다. 나중을 위해서요..-_-;;
혹시나 이거 밑바탕으로 될지 압니까??? ^-^;;
#include<iostream.h>
int main()
{
	cout<<"마방진을 짭시다~ 수를 입력하세요.(1-10)\n";
	int mab;
	cin >> mab;
	int mbang[9][9];
	if(mab%2!=0)
	{
		int i,j;
		for(i=0;i<mab;i++)
		{
			for(j=0;j<mab;j++)
			{
				mbang[i][j]=0;
				cout<< mbang[i][j];
			}		
			cout<<endl;
		}
		cout<<endl;
		int a=0,k=0;
		for(i=0;i<mab;i++)
		{
			for(j=0;j<mab;j++)
			{
				int t=mab/2;
				mbang[a][t]=1;
				int k;
				for(k=0;k<mab*mab && a-1>0;k++)
				{
					if(mbang==0 && t+1<mab)
						mbang[a-1][t+1]=k;
					else
						mbang[a-2][t+2-mab]=k;
				}
				if(a-1<0)
				{
					for(k=0;k<mab*mab;k++)
					{
						if(mbang==0 && t+1<mab)
							mbang[mab-1][t+1]=k;
						else
							mbang[mab-2][t+2-mab]=k;
					}
				}
				cout<< mbang[i][j];
			}
		}
		cout<<endl;
	}

	else
	cout << "다시 입력해야겠는데요~\n";
return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:43
Processing time 0.0153 sec