Perfect Square in Matlab
44 views (last 30 days)
Siraj on 4 Jul 2022
Edited: Siraj on 4 Jul 2022
It is my understanding that you want to know the easiest way to find whether a number is a perfect square or not.
For this first you can take the square root of the number and then see if the square root is a proper integer or not. We know that any integer when divided by one leaves zero as the remainder, therefore we can use the “modulo” function to find the remainder of the square root when divided by one and if the remainder is zero means that the number is a perfect square.
Refer to the documentation for more on modulo function in MATLAB.
n = 49;
%take the square root
sq_rt = sqrt(n);
% now check if the sq_rt is a proper integer or not
int_or_not = mod(sq_rt,1);
if(int_or_not == 0)
disp("Not a Perfect Square");
More Answers (3)
Karan Kannoujiya on 4 Jul 2022
You can use below code to check for a perfect square-->
%num---> number you want to check
disp('The number is perfect square number');
disp('The number is not a perfect square number');