如上图所示像要输出金字塔的C语言代码
#include<stdio.h>
void main()
{
int i = 1, j = 1, m, n;
m = 5;
for (i = 1;i <= m;i++)
{
for (j = 1;j <= m - i;j++)
printf(" ");
for (j = 1;j <= 2 * i - 1;j++)
printf("*");
printf("\n");
}
}
如上图所示想要输出随意数字的金字塔代码
#include<stdio.h>
void main()
{
int i = 1, j = 1, m, n;
printf("请输入m的值:");
scanf_s("%d", &m);
for (i = 1;i <= m;i++)
{
for (j = 1;j <= m - i;j++)
printf(" ");
for (j = 1;j <= 2 * i - 1;j++)
printf("*");
printf("\n");
}
}