求两个数的最大公约数和最小公倍数

来源:互联网 发布:中文编程系统 编辑:程序博客网 时间:2024/05/18 09:05
#include <stdio.h>#include <stdlib.h>int main(){int a = 16;int b = 12;if (a>b){int tmp;tmp = a;a = b;b = tmp;}if (a%b == 0){printf("最大公约数为:%d\n", b);printf("最小公倍数为:%d\n", a);}else{for (int i = b; i>0;i--)if ((a%i == 0)&&(b%i == 0)){printf("最大公约数为:%d\n",i );printf("最小公倍数为:%d\n", (a*b)/i);return 0;}}system("pause");return 0;}

运行结果:


原创粉丝点击