Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main() {
- int n;
- printf("Enter the number:\n");
- scanf("%d", &n);
- int sum = 0;
- for (int i = 1; i <= sqrt(n); i++) {
- if (n % i == 0) {
- if (n / i == i) {
- sum += i;
- } else {
- sum += i;
- sum += n / i;
- }
- }
- }
- sum -= n;
- if (sum == n) {
- printf("%d is a perfect number\n", n);
- } else {
- printf("%d is not a perfect number\n", n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement