how do i use the for loop for multiplication table?

4 ビュー (過去 30 日間)
babita thadari
babita thadari 2016 年 6 月 23 日
コメント済み: Jim Liu 2022 年 10 月 30 日
hi, i have tried to write the multiplication table for two, like this % multiplication table clc N = 1,2,3,4,5,6,7,8,9,10; for i = 1:N; fi=2*N; end but somehow it's not working. i don't want to use the fprintf command. please help i am new to MATLAB Thank You in advance

採用された回答

KSSV
KSSV 2016 年 6 月 23 日
% multiplication table
clc
N = 1:10 ;
fi = zeros(size(N)) ;
for i = 1:length(N);
fi(i)=2*N(i);
end
table1 = [N' fi']
% With out loop
N = 1:10 ;
fi = 2*N ;
table2 = [N' fi']

その他の回答 (2 件)

Chaitanya Krishna
Chaitanya Krishna 2021 年 9 月 3 日
a = input('Enter a number : ')
for (i=1:10);
fprintf('%d * %d = %d\n',a,i,(a*i));
end

Himanshu Chaudhari
Himanshu Chaudhari 2022 年 4 月 2 日
clc
clear
close
% multiplication table
N = 1:10 ;
AI=rand(size(N));
MI=input('Please enter a value for Multiplication table=');
for i=N
AI(i)=MI*N(i);
end
multiplication_table= [N' AI']

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by