Perfect number in C

In this program, you will check whether the number is perfect or not. a positive integer that is equal to the sum of its proper divisors excluding the number itself is called a perfect number.

for example divisor of 6 is 1,2, and 3 sum of divisor 1+2+3=6 hence 6 is the perfect number.

program for Perfect number in C

#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("\n enter the number");
scanf("%d",&n);
for(i=1;i<n;i++)
{
    if(n%i==0)
    {
        sum=sum+i;
    }
}
if(n==sum)
    printf("\n %d is perfect number",n);
else
    printf("\n %d is not a perfect number",n);
return 0;
}

output

enter the number:6
6 is perfect number