#include <stdio.h> #include <math.h>/* write a function that passes a variable of type A, B, two int, and returns a greatest common divisor of two values. For example: Input incoming (0, 5) function returns 5, incoming (10, 9) function returns 1, incoming (12, 4) function returns 4*///Subtract method int fuc (int m,int n) {int i=0,temp,x;while (m%2==0 && n% 2==0) //Determine how many 2 of M and n can be divisible by {m/=2;n/=2;i+=1;} if (m<n) //m Save the large value {temp=m;m=n;n=temp;} while (x) {x=m-n;m= (n>x)? n:x;n= (N<x), N:x;if (n== (m-n)) break;} if (i==0) return n;else return (int) POW (2,i) *n; The Euclidean int fuc2 (int m,int n) {int temp;if (m<n) {temp=m;m=n;n=temp;} while (n!=0) //divide {temp=m%n;m=n;n=temp;} return m;} int main () {int m,n;scanf ("%d%d", &m,&n);p rintf ("fuc:%d\n", Fuc (m,n));p rintf ("fuc2:%d\n", Fuc2 (M,n)); return 0 ;}
"C-language" greatest common divisor (more subtractive method) and (Euclidean method)