star pttern genration program in c laguage using while loop

Discussion in 'C' started by mrunalini, Aug 15, 2009.

  1. mrunalini

    mrunalini New Member

    Joined:
    Aug 15, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    /*write a program to genrate star pattern as shown below using while loop*/

    *
    **
    ***
    ****
    *****
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    It's not a very hard task to do.
    Don't ask us for answers to you homework.

    Show us your progress (your code till now), and we would be happy to help.
     
  3. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    If you are asking for this code, you are lazy to try it out...
    Hint - Use the value of variable i (if i = 0 to 5) to print "*" that many times...
    Trust me we can tell you the code, you'll pass your homework, but wont get programming!!
    Do it yourself..
     
  4. mrunalini

    mrunalini New Member

    Joined:
    Aug 15, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    :pleased:
     
  5. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    try it, paste it if you get it, if you don't, post what you got till then...
    these patten generating will get you how to use your code repeatedly....there are many levels to this * generation...so doing it will clear your programming concept...
    All the best...
     
  6. mrunalini

    mrunalini New Member

    Joined:
    Aug 15, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Programme:
    Code:
    #include<stdio.h>
    #include<conio.h>
    main( )                                                                        
    {  int i,j;                                                                   
       clrscr( );                                                                  
       i=1;                                                                       
       while(i<=5)                                                                
       {                                                                          
          printf("   ");                                                          
          j=1;                                                                    
          while(j<=i)                                                             
           {                                                                      
             printf(" * ");                                                       
             j++;                                                                 
           }                                                                      
           printf("\n");                                                          
           i++;                                                                   
       }                                                                          
        getch( );                                                                  
    }                                    
    
    
    O/P:
    Code:
        *
        *  *
        *  *  *
        *  *  *  *
        *  *  *  *  *
     
    Last edited by a moderator: Aug 16, 2009
  7. mrunalini

    mrunalini New Member

    Joined:
    Aug 15, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    thank u for rply ,
    i m beginner in c lang, but not at all lazy ok.














     
  8. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    :) Good...
    I recommend using for loop instead of while, as you can initialize, condition and increment/decrement in the same line, moreover you can skip any or all part of it (i.e. initialize, condtion and inc/decrement)
    thus for a programmer its more visible and clear to understand....
    Try doing this pattern...
    *
    **
    ***
    **
    *

    If you want i can give you lot of patterns to practice, which will help you improve your skills...
    Have fun...
     
  9. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Don't take it personally. We get a lot around here who are lazy, they think we're expert enough to do their homework for them but not expert enough to notice that's what we're doing. Your original message stated "write a program to genrate star pattern as shown below using while loop", which did rather take the form of a lazy person's post. Well done for solving the problem on your own!

    Next time, to avoid the same problem, it would be a good idea to post some code along with an explanation of where you're stuck. Say what the program isn't doing that you expect, what input you gave, and what the program should do, then we stand a good chance of solving it simply by looking at the code.
     
  10. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    well said xp...
     
  11. mrunalini

    mrunalini New Member

    Joined:
    Aug 15, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    it was specified in Q? 2 use while loop thts why i hav solved using while loop.
    i'll be thankful 2 u if i get some practice pattern.
    Have a nice day :charming:
     
  12. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Well, mayjune gave you one, you can come up with others; here are a few:
    Code:
    *
     **
      ***
       ****
    
    
    *   *
     * *
      *
     * *
    *   *
    
    ***
     ***
      ***
       ***
    
    
       ***
      ***
     ***
    ***
    
    * * ** *** ***** ******** *************
    
    ***.* **** * ***** ********* ** ****** ***** *** ******
    
     
  13. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    nice one's xp...try these if you need more let us know...it'll polish your thinking in tems of programming...
     
  14. BMuas

    BMuas New Member

    Joined:
    Mar 10, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hello all,

    I get how to do the
    *
    **
    ***
    and the
    ***
    **
    *

    but how do you do the
    ***
    **
    *
    and
    *
    **
    ***
     
  15. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    What, you can work out how to loop from 1-3 then 3-1, but you can't work out how to loop from 3-1 then 1-3??? (hint: IT'S THE OTHER WAY ROUND).
     
  16. BMuas

    BMuas New Member

    Joined:
    Mar 10, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    oh sorry about that. the formating wasnt correct ...seems like we cant add spacing.

    like i said, i dont understand how to do it the mirror (opposite of right angle)
    ......***
    ........**
    ..........*

    and dont know this too
    ........*
    ......**
    ....***
     
  17. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    OK, so how many spaces are there, and how many stars?
    Can you work out how to do a loop to each number, and NOT display a line feed between them?

    These pattern programs are really easy to do. Have a go and see how far you get. Don't just give up cos it takes more than three lines of code and a spot of head scratching.
     
  18. BMuas

    BMuas New Member

    Joined:
    Mar 10, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    oh so sorry for the late response, I got it done already...
    We went over it in class as notes. Helps with studying in our new chapter and assignments.
     
  19. <Dritf3r>

    <Dritf3r> New Member

    Joined:
    May 14, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student, Bursar : Denel Dynamics
    Location:
    South Africa
    What people need to realize is, these forums are not to obtain answers for homework exercises. To master programming, you need to show initiative and be dedicated. Yes, we all get stuck every now and again, but we don't just put up a post asking for an entire answer. We go to fellow programmers with chunks of code to show our progress. So to all fellow programmers and coders, SHOW INITIATIVE! practice makes perfect! . There are numerous programming resources out there. Use them!

    Just remember one thing, you will learn the right way through the hard way.

    Regards
    <Drift3r>:nice:
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice