i have a program that calculates and prints Pascal's triangle. the lines line up on the left side of the screen. how do i get the triangle form on the screen?
1
1 1
1 2 1
1 3 3 1
i have a program that calculates and prints Pascal's triangle. the lines line up on the left side of the screen. how do i get the triangle form on the screen?
1
1 1
1 2 1
1 3 3 1
Use a counter to determine the number of spaces before printing the item in the triangle. You start with say 5 spaces and then count down and your triangle will be aligned properly.
pointer = NULL
printing the traingle upside down will be slightly easier .
Doing your math right also will help.
You cannot center 1 character over the center of 2 characters.
It is impossible in text mode. This means you have to do:
1,3,5,7 and so on for your row lengths. Thus:
1) Find the length of the longest line.
2) subtract 1 + (2*current line number) and that is the number of spaces you need total. Divide this in half, and that's the number of spaces you need to preceed your "line" with.
Example:
Longest line:
123454321 = 9 characters
For line 0, we do this:
line = 0;
space = (9 - (1+(line)))/2 ;
thus, space is 4.
____1 line 0
___121 line 1
__12321 line 2
_1234321 line 3
123454321 line 4
See how that works out?
Quzah.