Azzera filtri
Azzera filtri

Write a function called bell that returns the first n rows of the Bell triangle, where n is an input argument. The function must return an n-by-n array where the the top left triangle contains the Bell triangle with each row of the Bell triangle posi

1 visualizzazione (ultimi 30 giorni)
"Write a function called bell that returns the first n rows of the Bell triangle, where n is an input argument. For a precise definition, see http://en.wikipedia.org/wiki/Bell_triangle. The function must return an n-by-n array where the top left triangle contains the Bell triangle with each row of the Bell triangle positioned diagonally—bottom-left-to-upper-right—and the bottom right triangle contains only zeros. If n is not a positive integer, the function returns an empty array.
program
function B = bell(n)
B(1,1) = 1;
for i=2:n
B(i,1) = B(1,end);
for j = 1:i-1
B(i-j,j+1) = B(i-j+1,j)+B(i-j,j);
end
end
end
error
Your function made an error for argument(s) -1
can any one help me advance wishes

Risposta accettata

Walter Roberson
Walter Roberson il 15 Giu 2015
Your code is not paying attention to the requirement,
If n is not a positive integer, the function returns an empty array.

Più risposte (1)

charu sharma
charu sharma il 27 Ago 2015
You should add a condition to check if n is a positive integer or not. Here is a complete solution of this program: http://farzicoders.blogspot.in/2015/08/write-function-called-bell-that-returns.html

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by