Check given number is perfect number or not

Perfect number is a number which is equal to sum of its divisor. For eg,divisors of 6 are 1,2 and 3. The sum of these divisors is 6. So 6 is called as perfect number

Write the Code in different languages in the comments, we will add this program in the comments section later

One comment on “Check given number is perfect number or not”


  • 18-R-0588

    #include
    int main(){
    int n1,n2,lcm,sum=0;
    printf(“enter n1”);
    scanf(“%d”,&n1);
    printf(“factors are”);
    for(int i=1;i<n1;i++){
    if(n1%i==0){
    lcm=i;
    printf(" %d\n",lcm);
    sum=sum+lcm;

    }
    }
    if(sum==n1){
    printf("number is perfect number %d",sum);
    }
    else{
    printf("number is not perfect number");
    }
    }