numbers 1 to 10 faculty in matlab

To compute the factorial of numbers 1 to 10 in MATLAB, we can use a for loop as follows:

main.m
for ii = 1:10
    fprintf('Factorial of %d is %d\n', ii, factorial(ii));
end
77 chars
4 lines

Here, we use the factorial function to compute the factorial of each number ii in the loop, and print it using the fprintf function. The output of this code would be:

main.m
Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 3 is 6
Factorial of 4 is 24
Factorial of 5 is 120
Factorial of 6 is 720
Factorial of 7 is 5040
Factorial of 8 is 40320
Factorial of 9 is 362880
Factorial of 10 is 3628800
224 chars
11 lines

related categories

gistlibby LogSnag