辗转相除法
作者:互联网
代码:
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int gcd(int a, int b){ int t; while(b!=0){ t = a%b; a = b; b = t; } return a; } int main(int argc, char *argv[]) { int a,b; scanf("%d%d",&a,&b); printf("%d,%d最大公约数:%d\n",a,b,gcd(a,b)); printf("%d,%d最小公倍数:%d",a,b,a*b/gcd(a,b)); return 0; }
运行结果:
标签:include,return,gcd,int,辗转,公倍数,printf,除法 来源: https://www.cnblogs.com/ZZG-GANGAN/p/14669941.html