IP-17.c (991B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 03 Jan 2026 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Write a C program that includes a user-defined function named isPerfect with the signature 8 int isPerfect(int num);. A perfect number is a positive integer that is equal to the sum of 9 its proper divisors, excluding itself. For example, 28 is a perfect number because the sum 10 of its divisors (1, 2, 4, 7, 14) equals 28. */ 11 12 #include <stdio.h> 13 14 int isPerfect(int); 15 16 int main() 17 { 18 int n; 19 printf("Enter the number: "); 20 scanf("%d", &n); 21 if (isPerfect(n)) 22 { 23 printf("\nInput %d is a Perfect Number.", n); 24 } 25 else 26 { 27 printf("\nInput %d is not a Perfect Number.", n); 28 } 29 return 0; 30 } 31 32 int isPerfect(int n) 33 { 34 if (n <= 1) 35 return 0; 36 int temp = 1; 37 int i; 38 for (i = 2; i <= n / 2; i++) 39 { 40 if (n % i == 0) 41 { 42 temp += i; 43 } 44 } 45 return temp == n; 46 }