Niloy007

Pranto's Problem 2

Mar 23rd, 2021
487
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5.     int n;
  6.     printf("Enter the number:\n");
  7.     scanf("%d", &n);
  8.     int sum = 0;
  9.     for (int i = 1; i <= sqrt(n); i++) {
  10.         if (n % i == 0) {
  11.             if (n / i == i) {
  12.                 sum += i;
  13.             } else {
  14.                 sum += i;
  15.                 sum += n / i;
  16.             }
  17.         }
  18.     }
  19.     sum -= n;
  20.     if (sum == n) {
  21.         printf("%d is a perfect number\n", n);
  22.     } else {
  23.         printf("%d is not a perfect number\n", n);
  24.     }
  25. }
RAW Paste Data