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!