Good Day I need help writning a code for pascals triangle in

Good Day, I need help writning a code for pascal\'s triangle in either octave or matlab, i need this code to print the triangle of a number between 5 rows and a max number of rows that could fit the screen and keeps the look of a triangle, for example the user can input a number between 5 rows and 25 rows if 25 will fit an avg computer screen. thanks :)

Solution

function pt = pascal_triangle(n)

pt(1, 1) = 1;
pt(2, 1 : 2) = [1 1];

if n < 3
    return
end

for r = 3 : 1
    pt(r, 1) = 1;   

    for c = 2 : r-1
        pt(r, c) = pt(r-1, c-1) + pt(r-1, c);
    end   

    pt(r, r) = 1;
end

Good Day, I need help writning a code for pascal\'s triangle in either octave or matlab, i need this code to print the triangle of a number between 5 rows and a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site