#include <iostream>
using namespace std;
void main()
{
int n,i,sum;
int mn,mx;
cout<<"Input the starting range or number : ";
cin>>mn;
cout<<"Input the ending range of number : ";
cin>>mx;
cout<<"The Perfect numbers within the given range : ";
for(n=mn;n<=mx;n++)
{
i=1;
sum = 0;
while(i<n)
{
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
cout<<" "<<n;
}
cout<<endl;
system ("pause");
}
using namespace std;
void main()
{
int n,i,sum;
int mn,mx;
cout<<"Input the starting range or number : ";
cin>>mn;
cout<<"Input the ending range of number : ";
cin>>mx;
cout<<"The Perfect numbers within the given range : ";
for(n=mn;n<=mx;n++)
{
i=1;
sum = 0;
while(i<n)
{
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
cout<<" "<<n;
}
cout<<endl;
system ("pause");
}
Test Data :
Input the starting range or number : 1
Input the ending range of number : 50
Expected Output :
The Perfect numbers within the given range : 6 28
c++ program to find the perfect numbers within a given number of range
Reviewed by Unknown
on
May 21, 2017
Rating:
No comments: