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