Perfect Square in Matlab
이전 댓글 표시
What is the most efficient way to check wether a number is a perfect square or not in matlab. Perfect square are 4,9,16 and so on
채택된 답변
추가 답변 (3개)
x = (1:20);
mod(sqrt(x), 1) == 0
Karan Kannoujiya
2022년 7월 4일
Hi Zaid,
You can use below code to check for a perfect square-->
%num---> number you want to check
y=sqrt(num);
z=ceil(y);
if(z==y)
disp('The number is perfect square number');
else
disp('The number is not a perfect square number');
end
Shivam Lahoti
2022년 7월 4일
you can check for perfect square by using the following check, however representable number might sparse if n is large enough.
if floor(sqrt(n)).^2 == n
카테고리
도움말 센터 및 File Exchange에서 Networks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!