#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(" ");有什么作用,因为删除了整个图形就变了
----------------解决方案--------------------------------------------------------
你的程序有很多错误,
以下是引用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这些了,
----------------解决方案--------------------------------------------------------
改了之后的代码,运行结果如图
#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");
}
}
}
----------------解决方案--------------------------------------------------------