View Code of Problem 3700

#include<stdio.h>
#include<math.h>
int main(){
	int i,k,t;
	double  a;

	while(scanf("%lf",&a)!=EOF,a)
	{
		int s[100]={0};
		for(k=i=0;i<8;i++)
		{
			if(a<pow(2,i))
			{
				k=i;    //位数;
				break;
			}
		}   
    	for(i=k-1;i>=0;i--)
			if(a-pow(2,i)>=0)
			{
				s[i]=1;
				a=a-pow(2,i);
			}  
       for(t=i=0;i<k;i++)
			if(s[i]!=0)
			{
				t=i;
				break;
			}
			printf("%0.0f\n",pow(2,t));
	}
	return 0;			
}

Double click to view unformatted code.


Back to problem 3700