In: Computer Science
Write a program in a script file that creates m × n matrix with elements that have the following values. The value of each element in the last row is the number of the column. The value of each element in the last column is the number of row +1. For the rest of the elements, each has a value equal to the sum of the element below it and the element to the right.
Code:
Output:
Flow Chart:
Copyable Code:
n = input('Enter n value: ');
m = input('Enter m value: ');
%Fill zeros to array
A = zeros(n,m);
%loop to calculate the array values and fill them
for l = 1:n
for k = 1:m
if l == 1
%First row
A(l,k) = k;
elseif k == 1
%First column
A(l,k) =l;
else
%Elements left
A(l,k) = A(l-1,k) + A(l, k-1);
end
end
end
%Array
disp(A)