This problem required to achieve an output function number n rows pyramid.
Function interface definition:
void pyramid( int n );
Wherein n is a parameter passed in the user, a positive integer [1, 9]. Print out the function of the required number of n rows in the format as shown pyramid sample. Note that each number followed by a space.
Referee test program Example:
#include <stdio.h>
void pyramid( int n );
int main()
{
int n;
scanf("%d", &n);
pyramid(n);
return 0;
}
/* 你的代码将被嵌在这里 */
Sample input:
5
Output Sample:
. 1
2 2
. 3. 3. 3
. 4. 4. 4. 4
. 5. 5. 5. 5. 5
void pyramid( int n )
{
int i,j,s;
for(i=1; i <= n; i++)
{
s=n-i;
for(j=0;j<s;j++)
putchar(' ');
for(j=0; j < i; j++)
printf("%-2d", i);
putchar('\n');
}
}