Thursday, December 31, 2009

CODIES 1.2

First of all congrates to Guru and Prabhat for their perfect explanation to CODIES 1.1. You will get your treat (I am sorry for such a delay ) along with the winner of CODIES 1.3, the next post. I am sure you gonna love the next question, it's a good one. Right now here i am up with one another question - CODIES 1.2:-

int main()
{
printf("%s", "technoprax");
return 0;
}


Que : Output "prax" from the above code snippet. You are allowed only to add/replace 2 characters in the code.

15 comments:

  1. int main()
    {
    printf("%s\r ","technoprax");
    return 0;
    }

    ReplyDelete
  2. Sorry Anshika, but your solution doesn't seem to work. We need to output "prax". Adding a "\r" after "%s", brings the cursor back to starting of the line after printing the string.

    ReplyDelete
  3. after \r I had put 6 spaces which are not visible in my comment...will that be valid?

    ReplyDelete
  4. ohk. Good approach. But the problem clearly states that we are allowed only to add/replace only 2 characters.Solution is very, just look at the basics.

    ReplyDelete
  5. Okey...This works...

    The two changes suggested in the code are :
    1.Delete 'n'
    2.Replace 'o' with '\r'

    int main()
    {
    printf("%s", "tech\rprax");
    return 0;
    }

    Thanx anshika for bringing that \r into the scene...cool thing :)

    ReplyDelete
  6. int main()
    {
    printf("%s", "techno\rprax");
    return 0;
    }

    -HITANSHU

    ReplyDelete
  7. here is my code

    int main()
    { clrscr();
    printf("%s","tech\rprax");
    getch();
    return 0;
    }

    i have replaced 2 characters "no" with "\r".
    and the output is "prax"

    ReplyDelete
  8. Ok guys, its gud to see you all brainstorming.
    @Pravy, Hitman and Akank : your answers are right. They do output "prax". But "\r" was not what I wanted to highlight through this post. :)

    The most correct solution to this question is very basic and highlights some intricacies of C. You all know the answer, its just that you are not aware of it. :)

    Enjoy Coding !!!

    ReplyDelete
  9. int main()
    {
    printf("%s","technoprax"+6);
    return 0;
    }

    ReplyDelete
  10. Congrates prabhat, that is the right answer. This was what I was trying to highlight in this question. Please explain your answer.

    ReplyDelete
  11. while outputting a string using %s the option "+n" helps us to skip 'n' characters from beginning of the string supplied & displays the rest of the string.

    ReplyDelete
  12. int main()
    {
    printf("%s", "{techno}prax");
    return 0;
    }

    ReplyDelete
  13. P.S. I'm a chemical engg...:P

    ReplyDelete
  14. @V : sorry, your solution is wrong.

    ReplyDelete
  15. @prabhat : I think we can relate it with starting address of string and shifting it. Just a guess...

    ReplyDelete