Advertisement
tdttvd

04_19

Dec 8th, 2021
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. bool check(int n)
  5. {
  6.     int sum = 0;
  7.     for (int i = 1; i < n; i++)
  8.     {
  9.         if (n % i == 0)
  10.             sum += i;
  11.     }
  12.     if (sum == n)
  13.         return true;
  14.     else
  15.         return false;
  16. }
  17.  
  18. int main()
  19. {
  20.     int a, b;
  21.     scanf("%i %i", &a, &b);
  22.     int count = 0;
  23.  
  24.     for (int i = a; i <= b; i++)
  25.     {
  26.         if (check(i))
  27.         {
  28.             printf("%i ", i);
  29.             count += 1;
  30.         }
  31.     }
  32.  
  33.     if (count == 0)
  34.         printf("0");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement