Write a program to check whether a number is perfect or not.


Input


#include <stdio.h>

int main()
{
    int num,loop;
    int sum;

    printf("Enter a number: ");
    scanf("%d",&num);

    
    sum=0;

    for(loop=1; loop<num;loop++)
    {
        if(num%loop==0)
            sum+=loop;
    }

    if(sum==num)
        printf("%d is a perfect number.\n",num);
    else
        printf("%d is not a perfect number.\n",num);

    return 0;
}




Output


Enter a number: 6
6 is a perfect number.

No comments:

Post a Comment