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;
}
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14675792.html