i tried to find if there are perfect numbers in the code stating that 1 should be square of other in the same matrix or array
1 回表示 (過去 30 日間)
古いコメントを表示
採用された回答
Swaroopa
2022 年 8 月 28 日
編集済み: Swaroopa
2022 年 8 月 28 日
Hi Hannah,
You can sort the array or matrix and then use the same code.
You can also use indentation rules for better clarity.
function output = squared(arr)
n=length(arr)
output=false
for i=1:n
for j=i:n
if arr(i)*arr(i)==arr(j)
output=true
break
else
output=false
end
end
end
end
Hope it helps
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!