Need Help on Homework

Hi
I am having a bit stuggle with my homework problems.
can someone please help me solve these and explain how each program works thanks!

5. Create three columns. The first should have the ints 10 down to 1, the second should have their squares, and the third should say if the square is over fifty or not.

9. Create your very own Christmas tree with ten rows using nested for loops:


10. Write a program that counts the number of digits in an arbitrarily large integer. Hint: This is a short program (I did it in ten lines) that should make use of a while loop.
Last edited on
For 5 and 9: I find that getting some graph paper out and treating each square as a character cell is useful. You can then draw what you want to see and count the number of spaces around things.

For example, a tree can be thought of as three triangles packed next to each other:

+---+
|A /|\
| / | \
|/B |C \
+---+---+

Triangle A is made by printing out spaces, while triangle(s) B+C is made of asterisks (or whatever it is your professor asked you to use).

Problem 10 is a variation of the "get the digits of an integer" problem. Remember that you can use the remainder operator (%) to get the least-significant digit and the integer division operator (/) to get rid of the least-significant digit.
123%10 --> 3
123/10 --> 12

Hope this helps.
Topic archived. No new replies allowed.