JeffGrigg icon

Pascal's Triangle Question

JeffGrigg | PRO | 11/07/18 12:03:54 PM UTC | 0 ⭐ | 1018 👁️ | Never ⏰ | []
text |

1.09 KB

|

None

|

0 👍

/

0 👎

A Pascal’s triangle with levels 0 to 4 is shown below. Level 0 has a single value, and each value on
subsequent levels is the sum of the two entries diagonally above in the previous level of the triangle. For
example, the value 6 in level 4 is the sum of the values 3 and 3 in level 3.
          1       level 0
        1 1      level 1
       1 2 1     level 2
      1 3 3 1    level 3
     1 4 6 4 1   level 4
 Complete function pascalVector below to return the row vector corresponding to a specified level of
Pascal’s triangle. For example, if level lev is 4, then the returned vector must be [1, 4, 6, 4, 1]. Assume
that lev is a non-negative integer. The only Matlab built-in functions allowed are zeros, ones, and length.
Do not use the formula for binomial coefficients to solve this problem. Use a loop (or loops): the vector
for each level is based on the vector from the previous level.
function p = pascalVector(lev)
 % p is the vector corresponding to level lev of Pascals triangle
 .
 "Old Test Question" from http://www.cs.cornell.edu/courses/cs1112/2015sp/Exams/final/oldQs.pdf

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎