c++编程用循环结构语句编程并输出下图,其行数和每行的数据个数有键盘给出. 例如:5 8

2025-04-02 10:21:57
推荐回答(1个)
回答1:

您好,这样的:
#include
#include

void main()
{
int m = 0, n = 0;
int i = 0, j = 0, k = 0;

scanf("%d%d",&m,&n);
for (i = -m; i <= m; i++)
{
for(k = 0; k < m - abs(i) + 1; k++)
printf(" ");
for(j = 0; j < n; j++)
{
if ( i == 0)
printf("*");
else
printf("%d", m - abs(i) + 1);
}
printf("\n");
}

}