#include <stdio.h> void starLine( int n ) { int j; for ( j=0; j<n; j++ ) putchar('*'); putchar('\n'); } void starBlock( int r, int c ) { int j; for ( j=0; j<r; j++ ) starLine( c ); } void pyramid( int blocks ) { int b=0; for ( b=1; b<=blocks; b++ ) starBlock( b, 2*b-1 ); } int main(int argc, char *argv[]) { pyramid( 7 ); system("PAUSE"); return 0; }
Comments:
The loop counter in pyramid()
should start at one because it describes
the number of rows in each block.
The first block has one row.
If you want, adjust the number of stars in each row to improve the appearance of the pyramid.