bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / practice-c / pc-ip-17.c

pc-ip-17.c (639B)


      1 /*
      2  * Question 17:
      3  * Write a C program that includes a user-defined function named isPerfect with the signature int isPerfect(int num);.
      4  */
      5 
      6 #include <stdio.h>
      7 
      8 int isPerfect(int);
      9 
     10 int main()
     11 {
     12     int num;
     13     printf("Enter the number : ");
     14     scanf("%d", &num);
     15     if (isPerfect(num))
     16     {
     17         printf("\nInput '%d' is a perfect number.", num);
     18     }
     19     else
     20     {
     21         printf("\nInput '%d' is not a perfect number.", num);
     22     }
     23     return 0;
     24 }
     25 
     26 int isPerfect(int n)
     27 {
     28     int i, sum = 0;
     29     for (i = 1; i <= n / 2; i++)
     30     {
     31         if (n % i == 0)
     32         {
     33             sum += i;
     34         }
     35     }
     36     return sum == n;
     37 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror