当前位置:首页>维修大全>综合>

求一份经典C语言代码大全(牛逼的简短的c语言代码)

求一份经典C语言代码大全(牛逼的简短的c语言代码)

更新时间:2024-03-17 13:06:24

求一份经典C语言代码大全

#include <stdio.h>int GCD(int m, int n);int LCM(int m, int n);main(){ int m = 0, n = 0; scanf("%d %d",&m,&n); while(m != 0 && n != 0){ printf("GCD = %d, LCM = %d ",GCD(m,n),LCM(m,n)); scanf("%d %d",&m,&n); } }int LCM(int m, int n){ int lcm = 0; if(m>n){ lcm = m; } else lcm = n; while(lcm%m==0 && lcm%n==0){ lcm++; } return lcm;}int GCD(int m, int n){ int a = 0; int i = 0; int gcd = 0; if(m>n){ a = n; } else a = m; for(i = 0;i<=a;i++){ if(m%i==0&&n%i==0) gcd = i; } return gcd;}

更多栏目