Question

Discussion in 'C++' started by Venkat, Aug 26, 2004.

  1. Venkat

    Venkat Guest

    Hi All,

    I have the following problem please help me in solving this.

    #include <stdio.h>
    main()
    {
    int i, n=20;
    for(i=0;i<n; i--)
    {
    printf("-");
    }
    }

    Only one character in the above needs to be modified such that the character
    '-' will be printed 20 times.
    People say there are 3 ways of doing it but i could figure out only one way
    given below.

    #include <stdio.h>
    main()
    {
    int i, n=20;
    for(i=0;i<n; n--)
    {
    printf("-");
    }
    }

    Can someone crack the other 2 possibilities.


    regards,
    Venkat
    Venkat, Aug 26, 2004
    #1
    1. Advertising

  2. > Can someone crack the other 2 possibilities.

    Here is one:

    for(i=0;-i<n; i--)
    Niels Dybdahl, Aug 26, 2004
    #2
    1. Advertising

  3. Venkat

    Venkat Guest

    "Niels Dybdahl" <-graphics.com> wrote in message
    news:412def76$0$182$...
    > > Can someone crack the other 2 possibilities.

    >
    > Here is one:
    >
    > for(i=0;-i<n; i--)
    >


    Niels thanks for a quick response, the 2nd possibility

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

    we just need the 3rd one.
    Venkat, Aug 26, 2004
    #3
  4. Venkat wrote:
    > "Niels Dybdahl" <-graphics.com> wrote in message
    > news:412def76$0$182$...
    >
    >>>Can someone crack the other 2 possibilities.

    >>
    >>Here is one:
    >>
    >>for(i=0;-i<n; i--)
    >>

    >
    >
    > Niels thanks for a quick response, the 2nd possibility
    >
    > is for(i=0;i<n;n--)
    >
    > we just need the 3rd one.


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

    Victor
    Victor Bazarov, Aug 26, 2004
    #4
  5. Venkat

    Old Wolf Guest

    "Venkat" <> wrote:
    >
    > #include <stdio.h>
    > main()
    > {
    > int i, n=20;
    > for(i=0;i<n; i--)
    > {
    > printf("-");
    > }
    > }
    >
    > Only one character in the above needs to be modified such that the character
    > '-' will be printed 20 times.
    > People say there are 3 ways of doing it but i could figure out only one way
    > given below.
    >
    > for(i=0;i<n; n--)


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

    PS. I don't think "for (i=0;-i<n; i--)" counts because that is
    adding a character, not changing one. Did you quote the original
    problem exactly? If it were "for(i=0; i<n; i--)" then you could
    change the space to a minus.
    Old Wolf, Aug 26, 2004
    #5
  6. "Venkat" <> wrote in message news:<1093531576.117124@sj-nntpcache-3>...
    > "Niels Dybdahl" <-graphics.com> wrote in message
    > news:412def76$0$182$...
    > > > Can someone crack the other 2 possibilities.

    > >
    > > Here is one:
    > >
    > > for(i=0;-i<n; i--)
    > >

    >
    > Niels thanks for a quick response, the 2nd possibility
    >
    > is for(i=0;i<n;n--)
    >
    > we just need the 3rd one.


    Piece of cake:

    #include <stdio.h>
    main()
    {
    int i, n=20;
    for(i=0;i+n; i--)
    {
    printf("-");
    }
    }
    Benjamin Dacko, Aug 27, 2004
    #6
  7. "Venkat" <> wrote in message news:<1093531576.117124@sj-nntpcache-3>...
    > "Niels Dybdahl" <-graphics.com> wrote in message
    > news:412def76$0$182$...
    > > > Can someone crack the other 2 possibilities.

    > >
    > > Here is one:
    > >
    > > for(i=0;-i<n; i--)
    > >

    >
    > Niels thanks for a quick response, the 2nd possibility
    >
    > is for(i=0;i<n;n--)
    >
    > we just need the 3rd one.


    #include <stdio.h>
    main()
    {
    int i, n=20;
    for(i=0;i+n; i--)
    {
    printf("-");
    }
    }
    Benjamin Dacko, Aug 27, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    591
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    646
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    942
    Scott Allen
    Oct 6, 2005
  4. Philip Meyer
    Replies:
    0
    Views:
    417
    Philip Meyer
    Nov 30, 2003
  5. Bit Byte
    Replies:
    1
    Views:
    836
    Teemu Keiski
    Jan 28, 2007
Loading...

Share This Page