zoukankan      html  css  js  c++  java
  • c语言 410 输出连续* \n

    实质为限制程序循环的次数。

    1、while语句

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

    2、while语句

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

    3、for语句

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

    4、for语句

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

    5、do语句

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

    6、do语句

    #include <stdio.h>
    
    int main(void)
    {
        int i = 1, j;
        puts("please input an integer.");
        printf("j = "); scanf("%d", &j);
        
        if (j > 0)
        {
            do
            {
                putchar('*');
                putchar('\n');
                i++;
            }
            while (i <= j);
        }
        return 0;
    }
  • 相关阅读:
    study os
    open source [license]
    work serises------------patch
    interest in history-----------先秦
    python学习-----------argparse
    problems fixed
    work serises------------adb 使用
    零碎积累之--------------java环境相关
    Hash Table Five Finish
    Hash Table Four
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14677465.html
Copyright © 2011-2022 走看看