Answer the question
In order to leave comments, you need to log in
How to find the GCD of two numbers?
How to find the greatest common divisor of two given numbers? I wrote the code for finding a common divisor, but I can’t select the common divisor.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int x1,x2,k,i=1,c=1;
setlocale(LC_ALL,"Russian");
cout<<"Введите первое число\n";
cin>>x1;
cout<<"Введите второе число\n";
cin>>x2;
cout<<"Введите максимальное число\n";
cin>>k;
while(i<=k){
if((x1%i==0 && x2%i==0) && ((x1%i==0)==(x2%i==0))){
c=i;
cout<<"Общий делитель -> "<<c<<endl;
}
i++;
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question