Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Venkat

    #1

    Question

    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





  • Niels Dybdahl

    #2
    Re: Question

    > Can someone crack the other 2 possibilities.

    Here is one:

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


    Comment

    • Venkat

      #3
      Re: Question

      "Niels Dybdahl" <ndy@fjern.dett eesko-graphics.com> wrote in message
      news:412def76$0 $182$edfadb0f@d text02.news.tel e.dk...[color=blue][color=green]
      > > Can someone crack the other 2 possibilities.[/color]
      >
      > Here is one:
      >
      > for(i=0;-i<n; i--)
      >[/color]

      Niels thanks for a quick response, the 2nd possibility

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

      we just need the 3rd one.






      Comment

      • Victor Bazarov

        #4
        Re: Question

        Venkat wrote:[color=blue]
        > "Niels Dybdahl" <ndy@fjern.dett eesko-graphics.com> wrote in message
        > news:412def76$0 $182$edfadb0f@d text02.news.tel e.dk...
        >[color=green][color=darkred]
        >>>Can someone crack the other 2 possibilities.[/color]
        >>
        >>Here is one:
        >>
        >>for(i=0;-i<n; i--)
        >>[/color]
        >
        >
        > Niels thanks for a quick response, the 2nd possibility
        >
        > is for(i=0;i<n;n--)
        >
        > we just need the 3rd one.[/color]

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

        Victor

        Comment

        • Old Wolf

          #5
          Re: Question

          "Venkat" <venkat_kp@yaho o.com> wrote:[color=blue]
          >
          > #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--)[/color]

          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.

          Comment

          • Benjamin Dacko

            #6
            Re: Question

            "Venkat" <venkat_kp@yaho o.com> wrote in message news:<109353157 6.117124@sj-nntpcache-3>...[color=blue]
            > "Niels Dybdahl" <ndy@fjern.dett eesko-graphics.com> wrote in message
            > news:412def76$0 $182$edfadb0f@d text02.news.tel e.dk...[color=green][color=darkred]
            > > > Can someone crack the other 2 possibilities.[/color]
            > >
            > > Here is one:
            > >
            > > for(i=0;-i<n; i--)
            > >[/color]
            >
            > Niels thanks for a quick response, the 2nd possibility
            >
            > is for(i=0;i<n;n--)
            >
            > we just need the 3rd one.[/color]

            Piece of cake:

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

            Comment

            • Benjamin Dacko

              #7
              Re: Question

              "Venkat" <venkat_kp@yaho o.com> wrote in message news:<109353157 6.117124@sj-nntpcache-3>...[color=blue]
              > "Niels Dybdahl" <ndy@fjern.dett eesko-graphics.com> wrote in message
              > news:412def76$0 $182$edfadb0f@d text02.news.tel e.dk...[color=green][color=darkred]
              > > > Can someone crack the other 2 possibilities.[/color]
              > >
              > > Here is one:
              > >
              > > for(i=0;-i<n; i--)
              > >[/color]
              >
              > Niels thanks for a quick response, the 2nd possibility
              >
              > is for(i=0;i<n;n--)
              >
              > we just need the 3rd one.[/color]

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

              Comment

              Working...