免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1665 | 回复: 6
打印 上一主题 下一主题

[C] 有关c语言的两道题~~~很简单的~ [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-04-15 00:59 |只看该作者 |倒序浏览
可是我不会哦~~~

1,在n介方正中填
1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1
其中n由用户自己定义.

2, 在n介方正中填
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
其中n由用户自己定义.
谢谢啦

论坛徽章:
0
2 [报告]
发表于 2003-04-15 10:28 |只看该作者

有关c语言的两道题~~~很简单的~

毛病

论坛徽章:
0
3 [报告]
发表于 2003-04-15 10:46 |只看该作者

有关c语言的两道题~~~很简单的~

分配内存我就不说了,现我把第二题的写出来;
int toprow,bottomrow,leftcol,rightcol;
int i,j,n;
int **a;
.
.
.
j = 1;
toprow = 0;
bottomrow = n;
leftcol = 0;
rightcol = n;
while((bottomrow>;toprow)&&(rightcol>;leftcol))
{
    for(i=leftcol;i<rightcol;i++)
    {
         a[toprow] = j;
         j++;
    }
    toprow ++;
    for(i=toprow;i<bottomrow;i++)
    {
         a[rightcol-1] = j;
         j++;
    }
    rightcol --;
    for(i=rightcol-1;i>;=leftcol;i--)
    {
         a[bottomrow-1] = j;
         j ++;
    }
    bottomrow --;
    for(i=bottomrow-1;i>;=toprow;i--)
    {
         a[leftcol] = j;
         j ++;
    }
    leftcol ++
}
.
.
.

论坛徽章:
0
4 [报告]
发表于 2003-04-15 10:51 |只看该作者

有关c语言的两道题~~~很简单的~

第一题也差不多
int toprow,bottomrow,leftcol,rightcol;
int i,j,n;
int **a;
.
.
.
j = 1;
toprow = 0;
bottomrow = n;
leftcol = 0;
rightcol = n;
while((bottomrow>;toprow)&&(rightcol>;leftcol))
{
for(i=leftcol;i<rightcol;i++)
{
a[toprow] = j;
}
toprow ++;
for(i=toprow;i<bottomrow;i++)
{
a[rightcol-1] = j;
}
rightcol --;
for(i=rightcol-1;i>;=leftcol;i--)
{
a[bottomrow-1] = j;
}
bottomrow --;
for(i=bottomrow-1;i>;=toprow;i--)
{
a[leftcol] = j;
}
leftcol ++ ;
j++;
}
.
.
.

论坛徽章:
0
5 [报告]
发表于 2003-04-15 14:05 |只看该作者

有关c语言的两道题~~~很简单的~

谢谢啦`~
可以只用数组解决吗??

论坛徽章:
0
6 [报告]
发表于 2003-04-15 16:36 |只看该作者

有关c语言的两道题~~~很简单的~

原帖由 "M仔" 发表:
谢谢啦`~
可以只用数组解决吗??

不明白你这句话的意思。

论坛徽章:
0
7 [报告]
发表于 2003-04-15 17:09 |只看该作者

有关c语言的两道题~~~很简单的~

没拉~~
谢谢你~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP