Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Automorphic number using MATLAB

Automorphic Number in MATLAB:

Definition:



An automorphic number (sometimes referred to as a circular number) is a number whose square "ends" in the same digits as the number itself. For example, 5^2 = 25, 6^2 = 36, 76^2 = 5776, 376^2 = 141376,and 890625^2 = 793212890625, so 5, 6, 76, 376 and 890625 are all automorphic numbers.

Code to check whether a number is automorphic number or not:

x=input('Enter the number');
y=x*x;
m=y;
Y=[];
Z=[];
while m>0
    b=rem(m,10);
    Y=[Y b];
    m=(m-b)/10;
end
n=x;
while n>0
    b=rem(n,10);
    Z=[Z b];
    n=(n-b)/10;
end
t=0;
for i=1:length(Z)
    if(Y(i)~=Z(i))
       t=t+1;
    end
end
if(t==0)
    disp('Yes, the number is Automorphic number');
else
    disp('No, the number is not Automorphic number');
end



Explanation of the code:


Code to print all the automorphic number from 1 upto an input number in MATLAB:

g=input('Enter the number');
A=[];
for x=1:g
y=x*x;
m=y;
Y=[];
Z=[];
while m>0
    b=rem(m,10);
    Y=[Y b];
    m=(m-b)/10;
end
n=x;
while n>0
    b=rem(n,10);
    Z=[Z b];
    n=(n-b)/10;
end
t=0;
for i=1:length(Z)
    if(Y(i)~=Z(i))
       t=t+1;
    end
end
if(t==0)
   A=[A x];
end
end


Reference video :

Algorithm to extract digits from a number in matlab:



No comments

Popular Posts

Followers