ACM (TJU) : 2841


#include <iostream>
#include <math.h>
using namespace std;

int main ()
{
    int n;

    while ( cin >> n && n ) {

        char a [22];
        int index = 0;

        while ( n ) {
            a [index++] = (n % 2) + '0';
            n /= 2;
        }

        int number = 0;

        for ( int i = 0; i < index; i++ )
            number += (pow (2, index - 1 - i) * (a [i] - '0'));

        printf ("%d\n", number);

        //printf ("%s\n", a);

    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s