Guest User

Untitled

a guest
Jan 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void perfectnumber(int num);
  4. int main(){
  5. int low,high,sum=0,temp;
  6. cout <<"Please enter two integer"<<endl;
  7. cout << "Integer 1: ";
  8. cin >>low;
  9. cout << "Integer 2: ";
  10. cin >>high;
  11. if(low>high){
  12. temp=low;
  13. low=high;
  14. high=temp;
  15. }
  16. for(low;low<high;low++)
  17. perfectnumber(low);
  18. }
  19. void perfectnumber(int num){
  20. int i,sum=0;
  21. for(i=1;i<=num-1;i++)
  22. if(num%i==0)
  23. sum=sum+i;
  24. if(sum==num)
  25. cout <<num<<" is the perfect number!"<<endl;
  26. }
Add Comment
Please, Sign In to add comment