#include <stdio.h> int main() { int i,j,n,c=0; for (i=4;i>0;i--) { for (j=0;j<i;j++) printf(" *"); c++; printf("\n"); for(n=0;n<c;n++) printf(" "); } }
[此贴子已经被作者于2018-7-13 14:43编辑过]
#include <stdio.h> int main( void ) { const unsigned n = 4; for( unsigned r=0,c=0; r!=n; r+c<2*n?++c:(++r,c=0) ) { if( r+c == 2*n ) putchar( '\n' ); else if( c%2==r%2 && c>=r ) putchar( '*' ); else putchar( ' ' ); } }