我编写的一个显示菱形的C程序

 1#include <stdio.h>
 2
 3int main()
 4{
 5    int row;
 6    int counter, m, n;
 7    printf( "Enter the row of the diamond: " );
 8    scanf( "%d"&row );
 9
10    //above the max line
11    for ( counter = 1; counter <= ( row - 1 ) / 2; counter++ )
12    {
13        for ( m = 1; m < ( row + 1/ 2 - ( counter - 1 ); m++ )
14            printf( " " );
15        for ( n = 1; n <= 2 * counter - 1; n++ )
16            printf( "*" );
17        printf( "\n" );
18    }

19    
20    //max line
21    for ( n = 1; n <=  row; n++ )
22            printf( "*" );
23    printf ( "\n" );
24
25    //below the max line
26    for ( counter = 1; counter <= ( row - 1 ) / 2; counter++ )
27    {
28        for ( m = 1; m <= counter; m++ )
29            printf( " " );
30        for ( n = 1; n <= row - ( m - 1 ) * 2; n++ )
31            printf( "*" );
32        printf( "\n" );
33    }

34    
35    return 0;
36}
原文地址:https://www.cnblogs.com/iPeterRex/p/1242590.html