×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Pascal's Triangle

## Pascal's Triangle

(OP)
Hello,

some time ago I started to learn Turbo Pascal.
Now I've got a complex question, for me that is.

I want to write a program that prints out Pascal's Triangle.
But I'm stuck since I started to figure out how to write this program.

The program has to ask the user how many rows it has to display, after that the program should give Pascal's Triangle up to the number of rows the user has determined.

I hope someone can help me with this problem.
I'm too stuck ;)

Thanks for helping me!

Pepijn de Brouwer

### RE: Pascal's Triangle

ok, and where are you stuck? Let's see what you have so far, and then we can fill in :)

Cheers,

Realm174

### RE: Pascal's Triangle

(OP)
As I told you, I got stuck from the start.
This is what I've got so far...

PROGRAM Pascalstriangle;
VAR counter,ammount:INTEGER;

PROCEDURE GiveRow(i:INTEGER);
BEGIN
WRITELN('Row',i);
END;

BEGIN
WRITE('Give number of rows: ');
FOR counter:=1 TO ammount DO
GiveRow(counter);
WRITE('Press ENTER to stop');
END.

I hope you can help me out, because I don't know what to do next.

Pepijn de Brouwer

### RE: Pascal's Triangle

Alright, not too much to start... :) I'm assuming you know how to determine the values of Pascal's triangle? Look at each row as an array of numbers. If all you want to do is print the result, then all you need to retain in memory is the current line and the previous line.

I'm sorry, I'm heading out for work, so I can't write the whole thing for you... I'll stop by tonight and see if anyone helped you, and if not, I'll be glad to assist. In the meantime, see if you can determine how to calculate the current row, based on the previous rows...

Things you know:

1st row has only one value of 1.

next rows always have one more value than the previous row.
(think of giving your program a limit in the number of row... you wouldn't want someone to enter 1 billion as a requested number of rows)

and instead of picturing your triangle as a triangle, look at it as a block... it will make it easier to figure out the calculations...

___
|_1_|___
|_1_|_1_|___
|_1_|_2_|_1_|___
|_1_|_3_|_3_|_1_|___
|_1_|_4_|_6_|_4_|_1_|

Shouldn't be too difficult :)

Cheers,

Realm174

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!