필터 지우기
필터 지우기

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 (최근 30일)
"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

채택된 답변

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

추가 답변 (1개)

charu sharma
charu sharma 2015년 8월 27일
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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by