辗转相除法
#include<stdio.h> int GreatestComDiv(int m,int n) { int r; while((r=m%n)!=0) { m=n; n=r; r=m%n; } return n; } int main() { printf("%d\n",GreatestComDiv(12,15)); printf("%d\n",GreatestComDiv(15,12)); return 0; }
#include<stdio.h> int GreatestComDiv(int m,int n) { int r; while((r=m%n)!=0) { m=n; n=r; r=m%n; } return n; } int main() { printf("%d\n",GreatestComDiv(12,15)); printf("%d\n",GreatestComDiv(15,12)); return 0; }