@zyro May be this solves your problem...............

#include <iostream>

using namespace std;

int main()
{
    int no;
    char digit[50];

    int counter=0;
    cin >> no;

    do {
        if ( no% 2 == 0) {
            digit[counter++]='0';
        }
        else
        {
            digit[ counter++ ]='1';
        }

        if ( no < 0 ){
            no = (1 - no)/2;
        }
        else if(no>0){
            no = -no/2;
        }

    }
    while ( no );

    for ( int i = counter- 1; i >= 0; i--) {
        cout << digit[ i ] ;
    }
    cout << endl;
    return 0;
}





On Sun, Jan 29, 2012 at 8:51 PM, saurabh singh <[email protected]> wrote:

> Use a pen and paper....:) Generate a few numbers in base -2 by hand.You
> will get the logic.
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT
> blog:geekinessthecoolway.blogspot.com
>
>
>
> On Sun, Jan 29, 2012 at 11:44 PM, Zyro <[email protected]> wrote:
>
>> 0
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
-Sharad Dixit
 B.Tech(IT)
 Indian Institute of Information Technology Allahabad
-----------------------------------------------------------------------------------------------------------------------------
"We aim above the mark to hit the mark."
~ Ralph Waldo Emerson

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to