Write a program which reads a positive integer value N and indicates if N is a perfect number or not (N is a perfect number if N = the sum of its divisors without the number itself).
Difficulty level

Video recording
This exercise is mostly suitable for students
#include<stdio.h>
#include<conio.h>
int main()
{
int N, i , sum;
sum = 0;
do{
printf("Enter an integer: ");
scanf("%d", &N);
}while(N <0);
for (i = 1; i< N; i++)
if (N%i == 0)
sum += i;
if (N == sum)
printf("%d is Perfect.\n",N);
else
printf("%d is not Perfect.\n", N);
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
