我需要编写一个程序来提示奇数正整数,并在由星号组成的页面上生成菱形;数字是高度,也是宽度......
我不确定在设置奇数和正数的参数后该怎么做...我不太确定如何使用imut
值并设置钻石数字使用该值
我有一个基本的钻石代码,但我不确定它有什么问题。
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int row, col, numstars;
int half, rate = 1;
printf("Please enter a positive odd integer.\n");
scanf("%d", &numstars);
for (row = 1; row <= numstars; row++)
{
half = numstars / 2;
for (col = 0; col < half + 1 - numstars; col++)
printf(" ");
for (col = 1; col <= 2 * numstars - 1; col++)
printf("*");
if ((numstars == (half + 1)))
rate = -rate;
numstars = numstars + rate;
printf("\n");
}
return 0;
}
答案 0 :(得分:0)
您在这里要求我们教您算法的基础知识。
最大的问题是,您在 <configSections>...</configsections>
循环中修改了numstar
...因此您获得了无限循环......
以下是我修复代码的方法:简化并区分两种情况
for