Advertisement

Perfect Number in MATLAB (Algorithm is concept & Concept is Power)

Perfect Number in MATLAB (Algorithm is concept & Concept is Power) Code to check whether a number is Perfect or not:

x=input('Enter the number');
y=0;
for i=1:x-1
if(rem(x,i)==0)
y=y+i;
end
end
if(y==x)
disp('Yes');
else
disp('No');
end

Print all perfect numbers from 1 to N:

g=input('Enter the number');
Y=[];
for x=1:g
y=0;
for i=1:(x/2)
if(rem(x,i)==0)
y=y+i;
end
end
if(y==x)
Y=[Y y];
end
end

Perfect number in MATLAB,Matlab code to check Perfect Number,How to check whether a number is perfect or not,Perfect Number MATLAB,MATLAB for Beginners,Matlab Basics,Basic concept of MATLAB,MATLAB fundamentals,

Post a Comment

0 Comments