zoukankan      html  css  js  c++  java
  • c语言 47 编写一段程序,显示小于输入的整数的所有2的乘方。

    1、do语句

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

    2、while语句

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

    3、for语句

    #include <stdio.h>
    
    #include <math.h>
    
    int main(void)
    {
        int i = 1, j;
        puts("please input an integer.");
        printf("j = "); scanf("%d", &j);
        
        for(pow(2,i); pow(2,i) < j; i++)
        {
            printf("%.f ", pow(2,i));
        }
        putchar('\n');
        
        return 0;
    }
  • 相关阅读:
    squid-正向代理
    SNAT、DNAT、NPT
    tcpdump
    静态路由
    基于状态的iptables
    路由
    firewalld 防火墙
    KVM 快照
    Iptables 防火墙
    老子《道德经》第六十二章
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14675792.html
Copyright © 2011-2022 走看看