一、运行结果;
二、源代码;
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>//声明函数;
//最大公约数;
int greatdivisor(int x, int y);//最小公倍数;
int leastmultiple(int x, int y);int main()
{//初始化变量值;int number1 = 0;int number2 = 0;int divisor = 0;int multiple = 0;//获取变量值;printf("请输入两个整数:");scanf("%d %d", &number1, &number2);//调用最大公约数函数;divisor = greatdivisor(number1, number2);//调用最小公倍数函数;multiple = leastmultiple(number1, number2);//输出结果;printf("%d和%d的最大公约数为:%d,最小公倍数为:%d\n", number1, number2, divisor, multiple);return 0;
}//实现最大公约数函数;
int greatdivisor(int x, int y)
{//初始化变量值;int interchange = 0;int result = 1;//判断;if (x < y){//交换位置;interchange = x;x = y;y = interchange;}//运算;result = x % y;//循环运算;while (result != 0){//替换;x = y;y = result;//取余;result = x % y;}//返回值;return y;
}//实现最小公倍数函数;
int leastmultiple(int x, int y)
{//初始化变量值;int result = 1;int interchange = 0;int m, n;//赋值;m = x;n = y;//判断;if (x < y){//交换;interchange = x;x = y;y = interchange;}//运算;result = x % y;//循环运算;while (result != 0){//交换;x = y;y = result;//取余;result = x % y;}//运算;m = m / y;n = n / y;y = m * n * y;//返回值;return y;
}