zoukankan      html  css  js  c++  java
  • c语言中绘制三角形

    1、

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, len;
        puts("please input the len.");
        printf("len = "); scanf("%d", &len);
        
        for (i = 1; i <= len; i ++ )
        {
            for (j = 1; j <= i; j ++ )
            {
                putchar('*');
            }
            putchar('\n'); 
        }
        return 0;
    }

    2、

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, len;
        puts("please input the len.");
        printf("len = "); scanf("%d", &len);
        
        for (i = 1; i <= len; i ++)
        {
            for (j = 1; j <= len; j ++)
            {
                if (j > (len - i))
                    putchar('*');
                else
                    putchar(' ');
            }
            putchar('\n');
        }
        return 0;
    }

     ↓

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, len;
        puts("please input an integer.");
        printf("len = "); scanf("%d", &len);
        
        for (i = 1; i <= len; i ++ )
        {
            for (j = 1; j <= (len -i); j ++ )
                {
                    putchar(' ');
                }
            for (j = 1; j <= i; j ++)
                {
                    putchar('*');
                }
            putchar('\n');
            
        }
        return 0;
    }

     

    3、

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, len;
        puts("please input the len.");
        printf("len = "); scanf("%d", &len);
        
        for (i = 1; i <= len; i ++ )
        {
            for (j = 1; j <= len; j ++ )
            {
                if (j <= (len - i + 1))
                {
                    putchar('*');
                }
            }
            putchar('\n');
        }
        return 0;
    }

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, len;
        puts("please input the len.");
        printf("len = "); scanf("%d", &len);
        
        for (i = 1; i <= len; i ++ )
        {
            for (j = 1; j <= (len - i + 1); j ++ )
                {
                    putchar('*'); 
                }
            putchar('\n'); 
        }
        return 0;
    }

    4、

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, len;
        puts("please input the len.");
        printf("len = "); scanf("%d", &len);
        
        for (i = 1; i <= len; i ++)
        {
            for (j = 1; j <= len; j ++)
            {
                if (j > (i - 1))
                    putchar('*');
                else
                    putchar(' ');
            }
            putchar('\n');
        }
        return 0;
    }

     ↓

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, len;
        puts("please input the len.");
        printf("len = "); scanf("%d", &len);
        
        for (i = 1; i <= len; i ++ )
        {
            for (j = 1; j < i; j ++ )
            {
                putchar(' ');
            }
            for (j = 1; j <= (len + 1 - i); j ++)
            {
                putchar('*');
            }
            putchar('\n');
        }
        return 0;
    }

  • 相关阅读:
    LeetCode 260
    LeetCode 258
    LeetCode 237
    LeetCode 226
    LeetCode 203
    LeetCode 202
    codeforces 7D
    codefroces 7C
    codeforces 7B
    codeforces 6E (非原创)
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14248183.html
Copyright © 2011-2022 走看看