Answer to Question #310899 in C++ for Secret Agent

Question #310899

The greatest common divisor, also known as GCD, is the greatest number that will, without a remainder, fully divide a pair of integers.


Now, I want you to make a program that will accept two integers and with the use of loops, print out their GCD. Make good use of conditional statements as well.


Off you go!


Input

A line containing two integers separated by a space.

6·9

Output

A line containing an integer.

3




1
Expert's answer
2022-03-17T09:37:37-0400






#include <iostream>
using namespace std;




int main()
{
	int number1,number2;
	cout<<"Enter two positve integer numbers: ";
	cin>>number1>>number2;


	for(int i=number1;i>=0;i--){
		if(number1%i==0 && number2%i==0){
			cout<<i<<"\n";
			break;
		}
	}




	system("pause");


	return 0;
}

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