A simple pascal triangle with 6 rows look like below
pascal triangle |
The numbers will be have to be generated in rows.
On the first row just place 1 and both its left hand side and right hand side is occupied by zeroes,though not showed in the above image.Every row in the triangle should have it's starting and ending number as zero.so our first row will be exactly like below.
0 1 0
to generate the numbers on the second row
1. write down the first zero from row 1 as it is. 0
1. write down the first zero from row 1 as it is. 0
= 1 |
2. next from the first row,add the first number with second number |
= 1 |
3. and then add the second number with the third number |
5. for generating the third row,we will have to execute the same steps that we followed earlier.
You can keep repeating this and generate as many rows you want in your triangle.
C# Implementation
Here goes the C# Implementation.
Console Output
Console window generating the Pascal triangle for 10 rows |
No comments:
Post a Comment