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
조회 수: 8 (최근 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!