DEV Community

realNameHidden
realNameHidden

Posted on

2 1 1 1 1

Perfect Number Program in C

For explanation watch video

Perfect Number :
In mathematics, a perfect number is a positive
integer that is equal to the sum of its positive divisors, excluding the number itself.
ex : 6 = 1,2,3 < 6

1+2+3 =6
ex: 5 : 1
sum = 1 !=5
5 is not perfect number
Perfect Numbers examples : 6,28,496,8128

Program to check given number is perfect or not:

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

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay