C语言实现求两数的最大公约数最小公倍数

来源:互联网 发布:新疆经济发展数据 编辑:程序博客网 时间:2024/06/05 02:11

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

备注:由于编译环境是VS2013所以scanf函数改为scanf_s函数

#include  "stdio.h"int main(){int a = 0, b = 0;int tempa, tempb, temp;scanf_s("%d %d", &a, &b);if (a == 0 && b == 0){printf("a,b can't be zero!");return 0;}tempa = a;tempb = b;if (a < b){a = tempb;b = tempa;}while (b != 0){temp = a % b;a = b;b = temp;}printf("最小公约数是:%d \n", a);printf("最小公倍数是:%d", tempa*tempb / a);getchar();getchar();return 0;}


0 0
原创粉丝点击