# Pascal triangle

#1

I have to write R code for creating pascal triangle. The code should such that if I enter, eg, i=400 , it should give me a pascal triangle for that.

Can anyone help me?

Pascal's Triangle
#2

This StackOverflow thread seems like it might be a useful fit!

#3

thanks. can you also tell me, how to obtain row sum of each row in pascal triangle that is created. the sum should be 2^n.

#4

From the stackoverflow thred @mara linked to:

``````pascalTriangle <- function(h) {
lapply(0:h, function(i) choose(i, 0:i))
}
``````

The run:

``````p = pascalTriangle(4)
unlist(lapply(p, sum))
#[1]  1  2  4  8 16
``````

and compare with

``````2**(0:4)
# [1]  1  2  4  8 16
``````

#5

Just a friendly reminder about community.rstudio.com's homework policy: FAQ: Homework Policy

#### TL:DR How to Ask a Homework Related Question:

1. Do not ask verbatim copy-paste questions
2. Explicitly mention the course you are taking.
3. If reasonable, be sure to ask your question as a reproducible example (reprex). Preferably using the `reprex`-package