Created
January 19, 2019 17:52
-
-
Save uysalserkan/54fcbc18df65c0bcf711123b8b25692f to your computer and use it in GitHub Desktop.
Find the perfect number between tow numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void perfectnumber(int num); | |
int main(){ | |
int low,high,sum=0,temp; | |
cout <<"Please enter two integer"<<endl; | |
cout << "Integer 1: "; | |
cin >>low; | |
cout << "Integer 2: "; | |
cin >>high; | |
if(low>high){ | |
temp=low; | |
low=high; | |
high=temp; | |
} | |
for(low;low<high;low++) | |
perfectnumber(low); | |
} | |
void perfectnumber(int num){ | |
int i,sum=0; | |
for(i=1;i<=num-1;i++) | |
if(num%i==0) | |
sum=sum+i; | |
if(sum==num) | |
cout <<num<<" is the perfect number!"<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment