using fprintf to display multiple values

11 ビュー (過去 30 日間)
carlton letts
carlton letts 2020 年 6 月 6 日
回答済み: Ameer Hamza 2020 年 6 月 7 日
i need help with displaying my factorial results
it should be displayed as: exanple The factorial of 3 is 6
heres my code
clear
clc
%the input numbers you want the factorial for%
numlist = input ( ' enter a list of numbers');
numbers = length (numlist);
results =zeros (1, numbers);
for i = 1: numbers;
for ii = i;
facn= prod(1:numlist(i))
fprintf(' The factorial of %.0f is %.0f\n\n',numbers,facn)
end
end

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 6 月 7 日
Change the line to
fprintf(' The factorial of %.0f is %.0f\n\n',numlist(i),facn)
% ^ use numlist(i) here.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by