c语言中计算小于某一整数的所有2的乘方

 

1、

#include <stdio.h>

int main(void)
{
    double i;
    puts("please input an integer.");
    printf("i = "); scanf("%lf", &i);
    double j = 1;
    
    while (pow(2.0,j) < i)
    {
        printf("%.f ", pow(2.0,j));
        j ++;
    }
    printf("\n");
    return 0;
}

 

#include <stdio.h>
#include <math.h>

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

 

posted @ 2021-01-05 15:01  小鲨鱼2018  阅读(233)  评论(0编辑  收藏  举报