Check whether the given number is Perfect Number or not.
#include<math.h>
void main() {
int i;
int number;
int sum = 1;
printf("Enter number: ");
scanf("%d", &number);
for(i = 2; i <= sqrt(number); i++) {
if(number % i == 0) {
if(number/i == i)
sum += i;
else
sum = sum + i + (number/i);
}
}
if(sum == number)
printf("%d is perfect number", number);
else
printf("%d is not perfect number", number);
}
0 Comments