您的位置:首页 > 编程语言 > C语言/C++

第四届 蓝桥杯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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: