Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ please add comments within each steps and need to be same output as the samp

ID: 3767705 • Letter: C

Question

c++ please add comments within each steps and need to be same output as the sample. Thanks.

Write a program that allows the user to enter as many sets of 2 numbers as needed. For each set of two numbers, compute the Greatest Common Factor (GCF) of the two numbers. The program should do the followings: Allow the user to enter as many sets as needed. After the user enters all the numbers, display each set of two numbers and the GCF for these two numbers. The function to find GCF must be a recursive function. Here is the definition: GCF (n,m) = m if m

Explanation / Answer

#include <iostream>

using namespace std;


int greatestCommonFactors(int num1, int num2);
  
int main()

{

int firstValue, secondValue, greatestFactor;

char continue;
  
do

{

cout<<"Please enter the first Value: ";

cin>>firstValue;
  
while(firstValue==0)

{

cout<<" the value cannot be zero, enter again: ";

cin>>firstValue;

}
  

cout<<" enter the second Value: ";

cin>>secondValue;
  

while (secondValue==0)

{

cout<<" Value cannot be zero, enter again: ";

cin>>secondValue;

}

greatestFactor=greatestCommonFactors(firstValue,secondValue);
  
cout<<greatestFactor<<endl;
  

cout<<"Do you want continue?(lowercase y/n) ";

cin>>continue;

}

while(continue=='y');
  
system ("pause");

return 0;

}

int greatestCommonFactors(int value1, int value2)

{

int commonFactor, maxRange;
  
if(value1>=value2)

maxRange=value1;

if(value2>=value1)

maxRange=value2;
  

for(int factor=1; factor<=maxRange; factor++)

{

if(value1%factor==0 && value2%factor==0)

commonFactor=factor;

}

return commonFactor;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote