Tuesday, March 5, 2024

33. Perfect number checking :—

33. Perfect number checking :—


#include<stdio.h>

int main()

{

    int i,n,r,sum;

    printf("enter a value of n ");

    scanf("%d",&n);

    sum=0;

    for(i=1;i<n;i++)

    {

        r=n%i;

        if(r==0)

        {

            sum=sum+i;

        }

    }

    if(sum==n)

    {

        printf("It is a perfect number");

    }

    else

    {

        printf("It is not a perfect number");

    }

    return 0;

}


No comments:

Post a Comment