根据接受的数字在控制台打印出各种大小的菱形
2008-03-08 12:41:35 来源:WEB开发网核心提示:#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
#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");
}
}
}
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");
}
}
}
[]
更多精彩
赞助商链接