• c语言 47 显示出小于输入的整数的所有2的乘方


    1、while语句

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

    2、for语句

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

    3、do语句

    #include <stdio.h>
    
    int main(void)
    {
        int i = 2, j;
        puts("please input an integer.");
        do
        {
            printf("j = "); scanf("%d", &j);
            if (j <= 2)
                puts("the range of j is : > 2 ");
        }
        while (j <= 2);
        
        do
        {
            printf("%d ", i);
            i *= 2;
        }
        while (i <= j);
        putchar('\n');
        
        return 0;
    }
  • 相关阅读:
    NSThread 多线程 三种方式
    CABasicAnimation 核心动画
    图片圆角属性
    GCD
    IOS 推送
    IOS 截图
    UIImage 截图
    UIImageView 动画
    AFN 判断网络状态
    Template 模式
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14680597.html
Copyright © 2020-2023  润新知