C++ program to check that enter number is perfect or not..
C++ program to check that enter number is perfect or not..
Perfect Number:
A positive integer that is equal to the sum of its proper divisor.
e.g 6 is the sum of 1,2 and 3 which are the proper divisor.
#include <iostream>
using namespace std;
int main()
{
int loopstart,usernum,result,label,x=1;
while(x!=0)
{
int sum=0;
cout<<"Enter number to check that the number is perfect number:"<<"\n";
cin>>usernum;
result=usernum;
for(loopstart=1; loopstart<=usernum/2; loopstart++)
{
if(usernum%loopstart==0)
{
sum=sum+loopstart;
}
if(result==sum)
{
cout<<usernum<<" "<<"number is perfect"<<"\n";
goto label;
}
}
cout<<"\n"<<usernum<<" "<<"number is not perfect"<<"\n";
label:
cout<<"press 0 for exit to continue press 1"<<"\n";
cin>>x;
}
return 0;
}
Comments
Post a Comment