write a c++ program to check weather the given number is a perfect number using functions
Answers
Answered by
1
int Example(int print)
{
int num=0;
for(int i=1;i<print;i++)
{
if(print%i==0)
{
num=num+i;
}
}
return num;
}
int main()
{
int a;
cout << "Enter a number: ";
cin >> a;
int b = Example(a);
if(b == a)
cout<<"\n Entered number is a perfect number \n";
else
cout<<"\n Entered number is not a Perfect Number \n";
}
{
int num=0;
for(int i=1;i<print;i++)
{
if(print%i==0)
{
num=num+i;
}
}
return num;
}
int main()
{
int a;
cout << "Enter a number: ";
cin >> a;
int b = Example(a);
if(b == a)
cout<<"\n Entered number is a perfect number \n";
else
cout<<"\n Entered number is not a Perfect Number \n";
}
Similar questions