int DivisorN[100];
int DivisorM[100];
int index1, index2;
int N, M;
void findDivisorOfN()
{
int i;
for(i = 1; i<=N/2; i++)
{
if(N%i == 0) {
DivisorN[index1++] = i;
}
}
DivisorN[index1++] = N;
}
void findDivisorOfM()
{
int i;
for(i = 1; i<=M/2; i++)
{
if(M%i == 0) {
DivisorM[index2++] = i;
}
}
DivisorM[index2++] = M;
}
int findGreatestCommonDivisor()
{ // Find the height Common divisor between N and M
int i, j;
for(i = index1-1; i>=0; i--)
{
for(j = index2-1; j>=0; j--)
{
if(DivisorN[i] == DivisorM[j])
{
return DivisorN[i];
}
}
}
}
int main()
{
scanf("%d %d",&N,&M);
findDivisorOfN();
findDivisorOfM();
printf("%d\n",findGreatestCommonDivisor());
return 0;
}
No comments:
Post a Comment