Answer to Question #298043 in C++ for Esu

Question #298043

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.




1
Expert's answer
2022-02-15T08:15:17-0500
#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!";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment