question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • clasicallyivycious@yahoo.com

    #1

    question

    Hi, all
    Can anyone plz. help me out with this problem
    Print : A
    B A
    A B A
    B A B A
    A B A B A

    with the help of "for loop"

  • Richard Bos

    #2
    Re: question

    clasicallyivyci ous@yahoo.com wrote:
    [color=blue]
    > Can anyone plz. help me out with this problem
    > Print : A
    > B A
    > A B A
    > B A B A
    > A B A B A
    >
    > with the help of "for loop"[/color]

    Yes. Undoubtedly someone can plz. help you out with that problem. I
    suggest you start with your classmates, and if they don't know the
    solution either, blag it off a sophomore. If all else fails and you're
    really desperate, perhaps you could ask your teacher. Only after you've
    done that, _and_ have at least some code to show for it, should you come
    back here and ask for help, _not_ for a hand-out.

    Richard

    Comment

    • David Resnick

      #3
      Re: question


      clasicallyivyci ous@yahoo.com wrote:[color=blue]
      > Hi, all
      > Can anyone plz. help me out with this problem
      > Print : A
      > B A
      > A B A
      > B A B A
      > A B A B A
      >
      > with the help of "for loop"[/color]

      int i;

      for (i=0; i < 1; i++) {
      printf("A\nB A\nA B A\nB A B A\nA B A B A\n");
      }

      OK, perhaps that isn't so helpful. Why don't you give it
      a try, and see what you come up with. This is a trivial
      problem, you'd learn lots more by doing your own
      homework. Post what you come up with if you still
      need help, if you make a good try people will assist
      you.

      -David

      Comment

      • clasicallyivycious@yahoo.com

        #4
        Re: question


        David Resnick wrote:[color=blue]
        >[color=green]
        > > with the help of "for loop"[/color]
        >
        > int i;
        >
        > for (i=0; i < 1; i++) {
        > printf("A\nB A\nA B A\nB A B A\nA B A B A\n");
        > }
        >
        > OK, perhaps that isn't so helpful. Why don't you give it
        > a try, and see what you come up with. This is a trivial
        > problem, you'd learn lots more by doing your own
        > homework. Post what you come up with if you still
        > need help, if you make a good try people will assist
        > you.
        >
        > The output is going to be:[/color]
        A
        B A
        A B A
        B A B A
        A B A B A i wanted to be in reverse fashion, that's okay , but
        i wanted to use something like: (i = 5; i <= 1; i--);

        Comment

        • Keith Thompson

          #5
          Re: question

          clasicallyivyci ous@yahoo.com writes:[color=blue]
          > Can anyone plz. help me out with this problem
          > Print : A
          > B A
          > A B A
          > B A B A
          > A B A B A
          >
          > with the help of "for loop"[/color]

          If we really wanted to punish you, the best way to do it would be to
          give you the code to solve the problem. You could turn it in, get
          credit for it, and learn nothing.

          You should have local resources that can help you with this. Talk to
          your instructor, to a teaching assistant, to fellow students. Try
          writing the program yourself. Learn.

          --
          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
          We must do something. This is something. Therefore, we must do this.

          Comment

          • OtavioCC

            #6
            Re: question

            #include <stdio.h>
            #include <math.h>

            #define UP 1
            #define DOWN 0

            void myPrintf(int in_length, int in_order)
            {
            int cont, cont2;
            char str[2] = "ab";

            if (in_order == UP) {
            for (cont = 1; cont < in_length; cont++) {
            for (cont2 = 0; cont2 < cont; cont2++) {
            if((cont2 % 2) == 0)
            printf("%c", str[0]);
            else
            printf("%c", str[1]);
            }
            printf("\n");
            }
            } else if (in_order == DOWN) {
            for (cont = in_length; cont > 0; cont--) {
            for (cont2 = 0; cont2 < cont; cont2++) {
            if((cont2 % 2) == 0)
            printf("%c", str[0]);
            else
            printf("%c", str[1]);
            }
            printf("\n");
            }
            }
            }

            int main(int ac, char**av)
            {
            myPrintf(5, UP);

            myPrintf(5, DOWN);
            }

            Comment

            • OtavioCC

              #7
              Re: question

              $ gcc foobar.c -lm
              $ ./a.out
              a
              ab
              aba
              abab
              ababa
              abab
              aba
              ab
              a

              Comment

              • Christopher Benson-Manica

                #8
                Re: question

                Keith Thompson <kst-u@mib.org> wrote:
                [color=blue]
                > If we really wanted to punish you, the best way to do it would be to
                > give you the code to solve the problem. You could turn it in, get
                > credit for it, and learn nothing.[/color]

                That would be an undue hardship on ourselves as well, however, as then
                any of us might have the misfortune of working for the successful
                cheater. Pointy-haired bosses are made, not born :-)

                --
                Christopher Benson-Manica | I *should* know what I'm talking about - if I
                ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

                Comment

                Working...