标题:[讨论]关于一个制造钻石型东西的问题
只看楼主
louisapple
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-4-6
 问题点数:0 回复次数:2 
[讨论]关于一个制造钻石型东西的问题

#include<stdio.h>
main()
{
int num;

while (num != 0){
if (num == 0)
return 0;
printf("Enter a number (3-77):\t");
scanf("%ld", &num);
while (num>77 || num<3){
printf("Enter error!\n");
printf("Please enter a number(3-77):");
scanf("%d", &num);
}
for (int i=0; i<=(num-1)/2; i++)
{
for (int k=0; k<=num/2-i; k++)
printf(" ");
for (int j=0; j<=2*i; j++)
printf("*");
printf("\n");
}
for (int w=0; w<=num/2; w++){
for (int m=-1; m<=w; m++)
printf(" ");
for (int n=1; n<=(num-2)-2*w; n++)
printf("*");
printf("\n");
}
}
},请问里面i<=(num-1)/2,k<=num/2-i,k<=num/2-i,w<=num/2,m<=w分别代表什么???因为我把数字改了以后有不同结果,还有printf(" ");有什么作用,因为删除了整个图形就变了

搜索更多相关主题的帖子: 钻石 制造 
2006-04-28 18:03
soft_wind
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:1430
专家分:0
注 册:2006-4-5
得分:0 

你的程序有很多错误,


以下是引用louisapple在2006-4-28 18:03:00的发言:

#include<stdio.h>
main()
{
int num;

while (num != 0){   /*既然num不等于0,又干吗if(num==0)?*/
if (num == 0)
return 0;
printf("Enter a number (3-77):\t");
scanf("%ld", &num); /*再看下num是整形还是长整形?*/
while (num>77 || num<3){
printf("Enter error!\n");
printf("Please enter a number(3-77):");
scanf("%d", &num);
}
for (int i=0; i<=(num-1)/2; i++)
{
for (int k=0; k<=num/2-i; k++)
printf(" ");            /*该语句用来输出空格,调整图形的位置*/
for (int j=0; j<=2*i; j++)
printf("*");
printf("\n");
}
for (int w=0; w<=num/2; w++){      /*没见过在这里定义的*/
for (int m=-1; m<=w; m++)

printf(" ");
for (int n=1; n<=(num-2)-2*w; n++)
printf("*");
printf("\n");
}
}
},请问里面i<=(num-1)/2,k<=num/2-i,k<=num/2-i,w<=num/2,m<=w分别代表什么???因为我把数字改了以后有不同结果,还有printf(" ");有什么作用,因为删除了整个图形就变了

你把你想要输出的图形想一下,自然就知道为什么有i<=(num-1)/2,k<=num/2-i,k<=num/2-i,w<=num/2,m<=w这些了,


对不礼貌的女生收钱......
2006-04-28 18:26
cxwl3sxl
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:495
专家分:129
注 册:2005-11-12
得分:0 
改了之后的代码,运行结果如图
#include<stdio.h>
main()
{
int num,i,k,j,w,m,n;
scanf("%ld", &num);
while (num != 0){
if (num == 0)
return 0;
printf("Enter a number (3-77):\t");
scanf("%ld", &num);
while (num>77 || num<3){
printf("Enter error!\n");
printf("Please enter a number(3-77):");
scanf("%d", &num);
}
for (i=0; i<=(num-1)/2; i++)
{
for (k=0; k<=num/2-i; k++)
printf(" ");
for (j=0; j<=2*i; j++)
printf("*");
printf("\n");
}
for (w=0; w<=num/2; w++){
for (m=-1; m<=w; m++)
printf(" ");
for (n=1; n<=(num-2)-2*w; n++)
printf("*");
printf("\n");
}
}
}


努力,哈哈,总有一天会变成高手~~~~~~因为我相信:没有办不到,只有想不到!http://t..cn/fpress
2006-04-28 18:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-60911-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.389754 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved