Write a function named SameNumberOfFactors that takes two positive integer arguments and returns 1 if they have the same number of factors and 0 if they have not the same number of factors.
#include<iostream>
using namespace std;
bool SameNumberOfFactors(int num1, int num2)
{
int count1=0;
int count2=0;
for(int i=1;i<=num1;i++)
{
if(num1%i==0)
count1++;
}
for(int i=1;i<=num2;i++)
{
if(num2%i==0)
count2++;
}
return count1==count2;
}
int main()
{
int num1,num2;
cout<<"Please, enter two positive integers: ";
cin>>num1>>num2;
if(SameNumberOfFactors(num1,num2))
cout<<num1<<" and "<<num2<<" have the same number of factors!";
else
cout<<num1<<" and "<<num2<<" have not the same number of factors!";
}
Comments
Leave a comment