问:用for语句怎么找出n以内的勾股数。
Afficher commentaires plus anciens
function num = ggs(n);
num = n;
a = [];
b = [];
c = [];
for i = 1:num
for j = 1:num
for k = 1:num
if i^2+j^2==k^2
a = [a i];
b = [b i];
c = [c k];
end
end
end
end
disp(['勾数有',num2str(a),'b=',num2str(b),'c=',num2str(c)])
gss(10)
a=3 4 6 8b=3 4 6 8c=5 5 10 10
输入数值只能出现这样的答案,我想abc能一起出现比如[a b c] = [3 4 5],请问该怎么改啊?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur 循环及条件语句 dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!