Advertisement
Centipede18

perfectNumber

Apr 1st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int divisor(int n){
  5.     int sum = 0;
  6.     for(int i = 1; i < n; i++){
  7.         if(n%i==0) sum += i;
  8.     }
  9.     if(sum == n) return 1;
  10.     else return 0;
  11. }
  12.  
  13. main(){
  14.     int a, b, check = 0;
  15.     cin>>a>>b;
  16.     for(int i = a; i <= b; i++){
  17.         if(divisor(i)) {
  18.             check = 1;
  19.             cout<<i<<' ';
  20.         }
  21.     }
  22.     if(check == 0) cout<<"0";
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement