Advertisement
JeffGrigg

Pascal's Triangle Question

Nov 7th, 2018
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. A Pascal’s triangle with levels 0 to 4 is shown below. Level 0 has a single value, and each value on
  2. subsequent levels is the sum of the two entries diagonally above in the previous level of the triangle. For
  3. example, the value 6 in level 4 is the sum of the values 3 and 3 in level 3.
  4.  
  5. 1 level 0
  6. 1 1 level 1
  7. 1 2 1 level 2
  8. 1 3 3 1 level 3
  9. 1 4 6 4 1 level 4
  10.  
  11. Complete function pascalVector below to return the row vector corresponding to a specified level of
  12. Pascal’s triangle. For example, if level lev is 4, then the returned vector must be [1, 4, 6, 4, 1]. Assume
  13. that lev is a non-negative integer. The only Matlab built-in functions allowed are zeros, ones, and length.
  14. Do not use the formula for binomial coefficients to solve this problem. Use a loop (or loops): the vector
  15. for each level is based on the vector from the previous level.
  16. function p = pascalVector(lev)
  17.  
  18. % p is the vector corresponding to level lev of Pascals triangle
  19.  
  20. .
  21.  
  22. "Old Test Question" from http://www.cs.cornell.edu/courses/cs1112/2015sp/Exams/final/oldQs.pdf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement