第四届 蓝桥杯C/C++ 高职 5公约数公倍数
2013-06-21 16:32
337 查看
/*求两个整数的最大公约数和最小公倍数的功能。*/
#include<stdio.h>
#include<iostream.h>
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void myfunc(int a, int b)
{
int m,n,r;
if(a<b) swap(&a,&b);
m=a;n=b;r=a%b;
while(r!=0)
{
a=b;b=r;
r=a%b;
}
cout<<a/b<<endl;
printf("%d\n",b); // 最大公约数
printf("%d\n", m*a/b); // 最小公倍数
}
int main()
{
int a,b;
cin>>a;
cin>>b;
myfunc(a,b);
return 0;
}
#include<stdio.h>
#include<iostream.h>
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void myfunc(int a, int b)
{
int m,n,r;
if(a<b) swap(&a,&b);
m=a;n=b;r=a%b;
while(r!=0)
{
a=b;b=r;
r=a%b;
}
cout<<a/b<<endl;
printf("%d\n",b); // 最大公约数
printf("%d\n", m*a/b); // 最小公倍数
}
int main()
{
int a,b;
cin>>a;
cin>>b;
myfunc(a,b);
return 0;
}
相关文章推荐
- 第四届 蓝桥杯C/C++ 高职 1、题目标题: 猜年龄
- 第四届 蓝桥杯C/C++ 高职 7、核桃的数量
- 2013年第四届蓝桥杯全国软件大赛本科A组c++预赛 题目及参考答案
- 用C++实现最小公倍数和最大公约数
- 2013第四届蓝桥杯 C/C++本科A组 排它平方数(2个数相乘为大数,大数位标记的方法)
- C++实验7——最大公约和最小公倍数
- 2013 蓝桥杯第四届c/c++B组 解题报告(完全解决第四题,代码有点长....)
- 2013第四届蓝桥杯预赛试题本科c++第39级台阶
- 第四届蓝桥杯初赛 C/C++ A组 3. 振兴中华 二叉树的深度遍历
- (c++)输入两个正整数m和n,求其最大公约数和最小公倍数。
- 第四届蓝桥杯C++A组——排它平方数
- sdut_java_C/C++训练1---最大公约数与最小公倍数
- c++实验7——项目2:最大公约和和最小公倍数
- 2013年第四届蓝桥杯试题(C/C++本科A组) 振兴中华
- 2013第四届蓝桥杯C++B组第二题:马虎的算式
- 2013年第四届蓝桥杯省赛C++B组——5、前缀判断
- 第六届蓝桥杯校内选拔赛C/C++高职组解题(6)
- C++实验7——最大公约和和最小公倍数
- 第十八周 【OJ问题 A: C++实验——最小公倍数和最大公约数】
- 2013第四届蓝桥杯 C/C++本科A组 真题答案解析