View Code of Problem 3700

#include<bits/stdc++.h>
using namespace std;
#define max 50
int main(){
	 int n;
	 while(cin>>n){
	 	if(!n)break;
	 	int i = 0,tmp,a[200] = { };
		while(n){
			tmp = (n%2);
			if(tmp==1){
				a[i++] = tmp;
				break;
			}
			else a[i++] = tmp;
			n/=2;	
		}
		int sum = 0,op = 1;
	 	for(int j = 0;j<i;j++){
	 		sum = sum + a[j]*op;
	 		op*=2;
		 }
	 	cout<<sum<<endl;
	 }

	
	return 0;
}

Double click to view unformatted code.


Back to problem 3700