编写函数求两个整数的最大公约数和最小公倍数。
1 #include <iostream> 2 using namespace std; 3 4 void fun(int a, int b){ 5 int temp; 6 int m = a * b; 7 if(a > b){ 8 temp = a; 9 a = b; 10 b = temp; 11 } 12 while(a){ 13 temp = a; 14 a = b % a; 15 b = temp; 16 } 17 cout<<"最大公约数:"<<b<<endl<<"最小公倍数:"<<m/b<<endl; 18 19 } 20 21 22 int main(){ 23 int a,b; 24 cout<<"输入两个数"<<endl; 25 cin>>a>>b; 26 fun(a,b); 27 return 0; 28 }
标签:10,cout,temp,int,公倍数,fun From: https://www.cnblogs.com/YUZE2001/p/17208456.html