Title Description
Description
A greatest common divisor of two numbers A and B are asked. 1<=a,b<=2^31-1
Enter a description input
Description
Two integers A and b
Outputs description output
Description
Greatest common divisor gcd (A, B)
Sample input to
sample
8 12
Greatest common divisor: for example, ask for a, b between a (A<B):
The first step: to find the remainder of B in addition to a, set to R,
The second step: judging R, if R is 0, then a is the greatest common divisor of both. If R is not 0, proceed to step three;
Step three: Assign A to B, assign R to a, and perform the first step.
Code:
#include <stdio.h>
int Max (int x,int y)
{
int r,a,b;
A=x;
B=y;
r=b%a;
Seeking greatest common divisor by the method of dividing
while (r!=0)
{
B=a;
c=0;
r=b%a;
}
return A;
}
int main ()
{
int n,m,i,j,count=0;
scanf ("%d%d", &n,&m);
printf ("%d\n", Max (n,m));
return 0;
}
1212 Greatest common divisor