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;
}