发一个输出星号菱形的程序代码
#include <stdio.h>#include<stdlib.h>
int main()
{
int i,j,num;
scanf("%d",&num);
for(i=-num/2;i<=num/2;i++)
{
for(j=-num/2;j<=num/2;j++)
{
if(abs(i)+abs(j)==num/2)
printf("*");
else
printf(" ");
}
puts("");
}
return 0;
}
结果:
20
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
Press any key to continue