Write a program that accepts a positive integer from keyboard and check if it is a perfect number.
A perfect number, p, is a positive integer that equals the sum of its divisors, excluding p itself. For example, 6 is a perfect number because the divisors of 6 (1, 2, and 3) sum to 6. There are actually only three perfect numbers less than 1000, and they are 6, 28 and 496.
Answers
Answered by
1
Answer:
Here You GO
Explanation:
#include <stdio.h>
int main() { int num,loop;
int sum; printf ( "Enter an integer number: " );
scanf ( "%d" ,&num);
sum=0; for (loop=1; loop<num;loop++)
{ if (num%loop==0) sum+=loop;
} if (sum==num)
printf ( "%d is a perfect number." ,num); else. printf ( "%d is not a perfect number." ,num);
Similar questions
History,
1 month ago
English,
1 month ago
English,
1 month ago
Hindi,
2 months ago
Social Sciences,
9 months ago