Write a C program to print Pascal Triangle. One of the most interesting Number Patterns is Pascal’s Triangle (named after Blaise Pascal, a famous French Mathematician and Philosopher). Adobe lightroom serial number crack key free. To build the triangle, start with “1” at the top, then continue placing numbers below it in a triangular pattern.
Active6 years, 9 months ago
Note : My Class Teacher gave me this question as an assignment.. I am not asked to do it but please tell me how to do it with recursion
Binomial coefficients can be calculated using Pascal's triangle:
Each new level of the triangle has 1's on the ends; the interior numbers are the sums of the two numbers above them.
Task: Write a program that includes a recursive function to produce a list of binomial coefficients for the power n using the Pascal's triangle technique. For example,
Input =
2 Output = 1 2 1
Input =
4 Output = 1 4 6 4 1
done this So Far but tell me how to do this with recursion..
janisz
5,41933 gold badges2626 silver badges5555 bronze badges
OlpersOlpers
20811 gold badge44 silver badges1111 bronze badges
closed as too localized by CrazyCasta, WhozCraig, Blastfurnace, KillianDS, 0x499602D2Dec 2 '12 at 0:34
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.
1 AnswerMethod 1:
Simplest way is to use the binomial coefficients. With this method, you have 1 recursive method:
Method 2:
This method use the construction with the formulae:
Here, the only function is recursive and compute one line at a time, storing these result in an array (in order to cache results).
Others methods:
There are some other exotic methods, using the properties of the triangle. You can also use the matrix way to generate it:
No code for it, as it would require a lot of base code (matrices, exponential of matrix, etc..), and it is not really recursive.
Pascal Triangle C Program Recursive Formula
On a side note, I think this problem is absolutely not the right problem to teach recursion. There are a lot of better cases for it.
Community♦
SynxisSynxis
8,01922 gold badges3232 silver badges6060 bronze badges
Pascal's Triangle Example Problems
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Uses Of The Pascal TriangleNot the answer you're looking for? Browse other questions tagged c++ or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |