Blogger Template by Blogcrowds

I saw this post in one of the blogs. Try solving

Here is a small C/C++ code snippet,

int n = 20;

for(i = 0; i < n; i--)

printf(”Hello World!”) ;

First try to find the answer to this program. It will obviously be an infinite loop or memory over flow or … The question is to make this snippet work and print the “Hello World!” 20 times correctly as if the statement i-- would have been i++.

The restriction however is to change only one ASCII character in this code. This means you can change, replace, move, introduce only one character to this program and the program still remains a valid C/C++ code. There are three possible ways I know to do this. May be there are more. If you find two then you are good, if three you are brilliant and if more than extraordinary ;)

17 Comments:

  1. Ramakrishnan said...
    >>> here are three possible ways I know to do this. May be there are more. If you find two then you are good, if three you are brilliant

    LoL...

    anyways, if you find how many ever answers in five mins you are good.
    if you take more than five mins, you are either jobless or trying out for a shift.
    Ramakrishnan said...
    am i the only one who is seeing the code wrongly ? or is it some notation in C? never saw this ...
    Arun said...
    dai.. karuthu pesama olunga answer'a adutha comment'la adi.. rascal..
    Arun said...
    oops.. sorry. now corrected.
    Ramakrishnan said...
    en assitant ganesh-ku theriyala na naan kalathula eranguvan :P
    Ramakrishnan said...
    ok one thing - not sure if it works -

    #define - +

    :P
    Arun said...
    i think he knows. He only gave me the blog url.
    Ramakrishnan said...
    ok.my #define was 200 chars long.
    only one ascii char ramak, only one
    :(
    Ramakrishnan said...
    gotcha.

    for( int i = 0; -i < n; i--)

    i < -n

    n = -20

    i am brilliant , i am brilliant !!!

    oops, internally afraid that i did something like that #define again :(
    Arun said...
    //for( int i = 0; -i < n; i--)//
    correct

    //i < -n//
    //n = -20//
    0 is greater than -20. so, no loop
    Ramakrishnan said...
    goyyala, if some body related to my project sees this space, they would be shit scared
    :P
    Ramakrishnan said...
    why am i taking this as an ego problem ?

    for( int i = 0; i < n; n--)
    U said...
    oh my god.. where am I ..
    Unknown said...
    ok, i didnt solve it .. i always cheat :))

    click here
    Arun said...
    jagan,
    :)

    Sen,
    ok, let me give the blog url which i was referring to
    http://haroonsaeed.wordpress.com/2008/01/14/try-your-coding-skills/
    Ganesh M said...
    Seems everybody is getting ready for the Hunt :) .. Happy ..
    Arun said...
    ganesh, forgot to update you. Would you like hunting in Finland? mail me.

Post a Comment



Newer Post Older Post Home