#include<stdio.h>
int main()
{
{
int num, i = 1, sum = 0;
printf("Enter a number: ");
scanf("%d", &num);
while (i < num) {
if (num % i == 0)
{
{
sum = sum + i;
}
i++;
}
if (sum == num)
printf("%d is a Perfect Number", i);
else
printf("%d is Non Perfect Number", i);
return 0;
}
Output:
Enter a number: 6
6 is a Perfect Number
Examples
The first perfect number is 6,
because 1, 2, and 3 are its proper positive divisors, and
1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of
all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6. The next perfect
number is 28 = 1 + 2 + 4 + 7 + 14.
No comments:
Post a Comment