In mathematics a perfect number is defined as a number which

In mathematics, a perfect number is defined as a number which is equal to the sum of its positive divisors excluding the number itself. For example, 6 is a perfect number since its are 1, 2, 3, and 6, and 1 + 2 + 3 = 6 but 10 is not a perfect number since its divisors are 1, 2, 5 and 10, and 1 + 2 + 5 = 8

Solution

The following code gives you the required solution for the given problem

number = 1;
while number <=1000
d = number-1;
sum = 0;
for c = 1:d
if(mod(number,c)==0)
sum = sum + c;
end
end
if(sum == number)
number
end
number = number+1;
end

Output:

Hope it helps, do comment your response.

 In mathematics, a perfect number is defined as a number which is equal to the sum of its positive divisors excluding the number itself. For example, 6 is a per

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site