• 我编写的一个显示菱形的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}
  • 相关阅读:
    004 eclipse-jee-2021-06-R-win32-x86_64的使用
    男神鹏:Mac系统下查看和生成SSH Key
    每天一个Python小技巧(2)
    每天一个Python小技巧(1)之JSON转义
    测试平台系列(26) 编写用例详情页(1)
    测试平台系列(25) 编写用例树
    iOS 骨架屏
    OC 拖拽View
    OC 配置全局PCH 文件
    iOS masonary 约束 做动画
  • 原文地址:https://www.cnblogs.com/iPeterRex/p/1242590.html
Copyright © 2020-2023  润新知