#include<iostream>
/*输入n时,请输单数
* 如3*3,5*5.......
* 该程序为单数宫图
*/
using namespace std;
int main()
{
int n;
cout<<"Please see out n is :";
cin>>n;
int sl[n][n];
for(int i=0,temp_a=n/2+1;i<n;i++,temp_a++)
{
if(temp_a>n-1)
temp_a=0;
for(int j=0;j<n;j++)
{
int sl_a,sl_b;
if(temp_a+j+1>n)
sl_a=temp_a+j+1-n;
else
sl_a=temp_a+j+1;
if(temp_a+n-j>n)
sl_b=temp_a+n-j-n;
else
sl_b=temp_a+n-j;
sl[j]=(sl_a-1)*n+sl_b;
if(j==n-1)
cout<<sl[j]<<endl;
else
cout<<sl[j]<<" ";
}
}
return 0;
}
c++九宫图小程序
-
- 帖子: 7
- 注册时间: 2006-09-01 12:41
- 联系:
- lovewine
- 帖子: 1233
- 注册时间: 2006-03-25 10:36
- 联系:
- 乾水居士
- 帖子: 54
- 注册时间: 2008-08-04 20:10
- 联系:
-
- 帖子: 27
- 注册时间: 2006-12-01 0:36
Re: c++九宫图小程序
谁来完善双数宫图
- 月下叹逍遥
- 论坛版主
- 帖子: 33994
- 注册时间: 2010-10-07 14:23
- 系统: Archdows10
- 来自: 某系某星某洲某国某省某市
- 联系:
Re: c++九宫图小程序
双偶数:greenhill 写了:谁来完善双数宫图
http://www.hsyyf.me/2012/04/%E5%B9%BB%E ... %EF%BC%89/
单偶数:
http://www.hsyyf.me/2012/05/%E5%B9%BB%E ... %EF%BC%89/
python版
浮生七十今三十,从此凄惶未可知
-
- 帖子: 27
- 注册时间: 2006-12-01 0:36
Re: c++九宫图小程序
#include<iostream>
/*输入n时,请输单数
* 如3*3,5*5.......
* 该程序为单数宫图
*/
using namespace std;
int main()
{
int n;
cout<<"Please see out n is :";
cin>>n;
for(int i=0,temp_a=n/2+1;i<n;i++,temp_a++)
{
if(temp_a>n-1)
temp_a=0;
for(int j=0;j<n;j++)
{
int sl_a,sl_b;
if(temp_a+j+1>n)
sl_a=temp_a+j+1-n;
else
sl_a=temp_a+j+1;
if(temp_a+n-j>n)
sl_b=temp_a+n-j-n;
else
sl_b=temp_a+n-j;
int sl[j];
sl[j]=(sl_a-1)*n+sl_b;
if(j==n-1)
cout<<sl[j]<<endl;
else
cout<<sl[j]<<" ";
}
}
return 0;
}
/*输入n时,请输单数
* 如3*3,5*5.......
* 该程序为单数宫图
*/
using namespace std;
int main()
{
int n;
cout<<"Please see out n is :";
cin>>n;
for(int i=0,temp_a=n/2+1;i<n;i++,temp_a++)
{
if(temp_a>n-1)
temp_a=0;
for(int j=0;j<n;j++)
{
int sl_a,sl_b;
if(temp_a+j+1>n)
sl_a=temp_a+j+1-n;
else
sl_a=temp_a+j+1;
if(temp_a+n-j>n)
sl_b=temp_a+n-j-n;
else
sl_b=temp_a+n-j;
int sl[j];
sl[j]=(sl_a-1)*n+sl_b;
if(j==n-1)
cout<<sl[j]<<endl;
else
cout<<sl[j]<<" ";
}
}
return 0;
}