A blog about programming and more programming.

Power of 2

with 2 comments

There was an online competition which required to find whether an integer(<2^31) entered is a power of 2 or not. The condition was that code should be as small as possible and should not use any semicolons.The input is terminated by end of file. What me and my room mate could get to was this :

main(int N){while(scanf(“%d”,&N)+1&&puts(N&N-1?”no”:”yes”)){}}

Though the best solution turned out to be this which was five character less than our solution :


Both are C programs, so you need to compile it using gcc(g++ won’t work).



Written by fR0DDY

February 10, 2009 at 6:23 PM

Posted in Beautiful Codes

Tagged with

2 Responses

Subscribe to comments with RSS.

  1. Hii !!!
    i hadnt seen such type of progg b4 ..

    nice1 ..
    u wer too close 2 the ans , or u wer having the right ans ..
    bad lluckk but brillient thought !


    February 13, 2009 at 9:42 AM

  2. this one opened new coding avenue fr me…


    April 13, 2009 at 1:06 PM

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: