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
0 Comments