Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JadeEyes

As a seasonal amusement some programmers like to print out a picture of a Christmas Tree looking like this. * *** * *** ***** * *** ***** ******* | ---+--- The tree consists of a series of tiers (three in this case) of increasing size. Write a program to produce such a display having prompted the user for thw number of tiers. You could try a few baubles on the tree (using o or O).

  • one year ago
  • one year ago

  • This Question is Closed
  1. eSpeX
    Best Response
    You've already chosen the best response.
    Medals 0

    What language are you writing in, what have you already tried, and what is giving you difficulties?

    • one year ago
  2. JadeEyes
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm using C language..!! I have no difficulties with the language itself..!! It's the logic that I lack..!! :P ..!! I just can't figue out how to use loops to achieve the wanted result..!! Can you help me with that..?? :)..!!

    • one year ago
  3. experimentX
    Best Response
    You've already chosen the best response.
    Medals 0

    print characters 3 characters next time 5 characters .. 7 ... etc etc

    • one year ago
  4. experimentX
    Best Response
    You've already chosen the best response.
    Medals 0

    i haven't programmed C for very long time. do something like this for(i=1;i<= 3, i++) { for(k=2i+1; k >= 1; k++) { for(j=1; j<= 2i+1) { print on center here } } }

    • one year ago
  5. JadeEyes
    Best Response
    You've already chosen the best response.
    Medals 0

    @eSpeX That's how tried doing it the first time using while loop : n = number of tiers while(n!=0) { printf( * \n) printf(O***O\n) n-- while(n!=0) { printf( * \n) printf( *** \n) printf( ***** \n) n-- } while(n!=0)...and so on..!! } But then it's kind of an infinite thing..!! ..@experimentX Thank you..!! However I don't really understand how it works..!!

    • one year ago
  6. experimentX
    Best Response
    You've already chosen the best response.
    Medals 0

    i don't seem to have c compiler in my computer .. mind if I send you python code?

    • one year ago
  7. JadeEyes
    Best Response
    You've already chosen the best response.
    Medals 0

    I'll try to decode it back to C..!! :P ..!! So don't worry..!! :) ..!!

    • one year ago
  8. experimentX
    Best Response
    You've already chosen the best response.
    Medals 0

    i ended up codig this in java public class Christmas{ public static void main(String args[]){ int i, j, k; for(i=1; i <= 3; i++){ for(j=i+1; j>=1; j--){ for(k=1; k<=2*i+1; k++){ if(k >= j && k <= -j + 2*(i+1)) System.out.print("*"); else System.out.print(" "); } System.out.println(""); } } } }

    • one year ago
  9. experimentX
    Best Response
    You've already chosen the best response.
    Medals 0

    still not working

    • one year ago
  10. experimentX
    Best Response
    You've already chosen the best response.
    Medals 0

    this is the working code in Java public class Christmas{ public static void main(String args[]){ int i, j, k, l=3; for(i=1; i <= l; i++){ for(j=i+1; j>=1; j--){ for(int x=1; x<=l-i; x++) System.out.print(" "); for(k=1; k<=2*l+1; k++){ if(k >= j && k <= -j + 2*(i+1)) System.out.print("*"); else System.out.print(" "); } System.out.println(""); } } } }

    • one year ago
    1 Attachment
  11. basking
    Best Response
    You've already chosen the best response.
    Medals 0

    The logic is that you want to build i triangles of heights j = 2, 3, 4, ... with row lengths k = 1, 3, 5, 7.... So you use nested for loops (go backwards starting with k).

    • one year ago
  12. basking
    Best Response
    You've already chosen the best response.
    Medals 0

    (Because you have to center it, it's important to note that the widest part of the tree should be 2*i+1)

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.