#include <stdio.h> #include <string.h> #include <math.h> int main(){ int a,index; char str[100]; //输入:1个整数a,1<=a<=100 while(scanf("%d", &a)!=EOF){ index=0; if(a==0) break; //处理1:将a转换成二进制字符串 while(a>0){ str[index++] = a%2+'0'; a /= 2; } //处理2:将二进制字符串的最低位转换成十进制 int len = strlen(str); for(int i=0; i<len; i++){ if(str[i]=='1'){ //输出:1个整数 printf("%d\n", (int)pow(2,i)); break; } } } } |
Double click to view unformatted code.