asterick homework problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shendelzare0020
    New Member
    • Feb 2007
    • 7

    asterick homework problem

    i couldn't find out the right source code for this one:
    output should be:

    problem number 1).
    enter number of asterisks:5
    *
    **
    ***
    ****
    *****
    try again?[Y/N]: __

    -------------------------------------------------------
    problem number 2).
    enter number of asterisks:5
    *****
    ****
    ***
    **
    *
    try again?[Y/N]: __
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    What have you written so far? What ideas do you have? What have you done in an effort to solve this problem alone?

    Comment

    • shendelzare0020
      New Member
      • Feb 2007
      • 7

      #3
      Originally posted by Ganon11
      What have you written so far? What ideas do you have? What have you done in an effort to solve this problem alone?
      I just encoded this:

      #include<stdio. h>
      #include<conio. h>
      void main (void)
      {
      int x,y;
      char choice;
      do{
      clrscr();
      printf("Enter number of asterisk:");
      scanf("%i",&y);
      for(x=1;x<=y;x+ +)
      {
      gotoxy(x*1,x*1+ 2);cprintf("*") ;
      }
      printf("\ntry again [Y/N]:");
      choice=getch();
      }while(choice== 'Y' || choice=='y');
      getch();
      }

      and the output is:
      *
      *
      *

      the output required is:

      Enter number of asterisks: 3
      *
      **
      ***
      try again [y/n]: __

      and the other one goes like this:
      Enter number of asterisks: 3
      ***
      **
      *
      try again [y/n]: __

      can you help me pls..i know you can
      i just got a little time left;
      submission will be tomorrow...
      thanks alot!!!

      Comment

      • rajesh6695
        New Member
        • Oct 2006
        • 96

        #4
        #include <stdio.h>
        #include <conio.h>
        int main()
        {
        int i,j,k;
        char ch;
        clrscr();
        printf("Enter the no : ");
        scanf("%d",&i);
        for(k=0;k<=i;k+ +)
        {
        for(j=0;j<k;j++ )
        {
        printf("*");
        }
        printf("\n");
        }

        printf("Second Format.....\n") ;
        for(k=0;k<=i;k+ +)
        {
        for(j=i;j>k;j--)
        {
        printf("*");
        }
        printf("\n");
        }
        printf("Press any key to continue....\n" );
        getch();
        return 0;
        }



        The above code will generate as both 1 and 2 tasks....
        Implement that to continue till user press N....By putting whole program in the Do-While loop....

        Loop should start after clrscr() and ends before press anykey to continue....

        Try....

        Comment

        • shendelzare0020
          New Member
          • Feb 2007
          • 7

          #5
          Originally posted by rajesh6695
          #include <stdio.h>
          #include <conio.h>
          int main()
          {
          int i,j,k;
          char ch;
          clrscr();
          printf("Enter the no : ");
          scanf("%d",&i);
          for(k=0;k<=i;k+ +)
          {
          for(j=0;j<k;j++ )
          {
          printf("*");
          }
          printf("\n");
          }

          printf("Second Format.....\n") ;
          for(k=0;k<=i;k+ +)
          {
          for(j=i;j>k;j--)
          {
          printf("*");
          }
          printf("\n");
          }
          printf("Press any key to continue....\n" );
          getch();
          return 0;
          }



          The above code will generate as both 1 and 2 tasks....
          Implement that to continue till user press N....By putting whole program in the Do-While loop....

          Loop should start after clrscr() and ends before press anykey to continue....

          Try....
          it just printed a single asterisk (*)
          will i use gotoxy?

          Comment

          • rajesh6695
            New Member
            • Oct 2006
            • 96

            #6
            Originally posted by shendelzare0020
            it just printed a single asterisk (*)
            will i use gotoxy?

            The output will be

            Enter the no : 5

            *
            **
            ***
            ****
            *****
            Second Format.....
            *****
            ****
            ***
            **
            *

            Press any key to continue....



            Thanks and Regards
            Rajesh G
            rajeshg@infotec hsw.com

            Comment

            • Ganon11
              Recognized Expert Specialist
              • Oct 2006
              • 3651

              #7
              Please refer to the following thread for our policy on double posting...



              The second thread has been deleted.

              Comment

              • shendelzare0020
                New Member
                • Feb 2007
                • 7

                #8
                Originally posted by rajesh6695
                The output will be

                Enter the no : 5

                *
                **
                ***
                ****
                *****
                Second Format.....
                *****
                ****
                ***
                **
                *

                Press any key to continue....



                Thanks and Regards
                Rajesh G
                rajeshg@infotec hsw.com
                hi rajesh thanks alot but the output goes like this
                enter no.5

                *
                second format...
                *****
                ****
                press any key to continue...

                Comment

                • Ganon11
                  Recognized Expert Specialist
                  • Oct 2006
                  • 3651

                  #9
                  You must have changed something significant in the code, because it gives the proper output for me (after minor modifications to make it compile in C++).

                  Comment

                  • shendelzare0020
                    New Member
                    • Feb 2007
                    • 7

                    #10
                    Originally posted by Ganon11
                    You must have changed something significant in the code, because it gives the proper output for me (after minor modifications to make it compile in C++).
                    I have just encoded what rajesh has written but the output did not go like that what i am expecting...by the way i am using a turbo c but i do not know if my compiler is c++ or a c compiler...pls help...

                    Comment

                    • nmadct
                      Recognized Expert New Member
                      • Jan 2007
                      • 83

                      #11
                      Originally posted by shendelzare0020
                      I have just encoded what rajesh has written but the output did not go like that what i am expecting...by the way i am using a turbo c but i do not know if my compiler is c++ or a c compiler...pls help...
                      TurboC is a plain C compiler. TurboC++ also exists and compiles C++. They're old but fine compilers.

                      TurboC is probably not ANSI-compliant because it was released in 1989 and the ANSI standard was finalized in 1990. However, they were tracking the standard as it developed and it shouldn't deviate too much. I would avoid using <conio.h> calls like gotoxy (clrscr is OK I guess) because they're non-standard (fewer compilers and fewer people will recognize them), but more importantly, they're not needed at all here for this very simple assignment. Conio is more for making full-screen applications, not for this kind of simple input-output console app.

                      Are you required to use TurboC? If not, you could download MinGW and see if it works with that. MinGW is a Windows-native version of the GCC C/C++ compiler. That's a lot of trouble though, probably easier to get TurboC working.

                      As for the program itself -- sorry, the posted code should work fine.

                      Comment

                      Working...