实现函数输出n行数字金字塔
#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>void pyramid(int n)
{int i,j,k;for (i=1; i<=n; i++){//输出左边空格,空格数为n-i for (j=1; j<=n-i; j++){printf(" "); } //每一行左边空格输完后输出数字,n行n个数字(数字后面有一个空格) for(k=1; k<=i; k++){printf("%d ",i); }printf("\n");}
} int main()
{ int n;printf("输入1~9的整数:\n");scanf("%d", &n);pyramid(n);return 0;
}