Here you will get a program for the perfect number in C.
A perfect number is a positive number which is equivalent to the entirety of every one of its divisors barring itself.
For instance:
28 is a perfect number as 1 + 2 + 4 + 7 + 14 = 28.
15 isn’t perfect number as 1 + 3 + 5 isn’t equivalent to 15.
Underneath I have shared a program to check whether a number is a perfect number or not.
Program
#include<stdio.h>
int main(){
int num,j,s=0;
printf("Enter a number:");
scanf("%d",&num);
for(j=1;j<num;++j){
if(num%j==0){
s=s+j;
}
}
if(s==num){
printf("Perfect Number");
}
else{
printf("Not perfect number");
}
return 0;
}
Output