最大公约数和最小公倍数求法
1 #include <iostream>
2 using namespace std;
3 int main()
4 {int hcf(int,int);
5 int lcd(int,int,int);
6 int u,v,h,l;
7 cin>>u>>v;
8 h=hcf(u,v);
9 cout<<"H.C.F="<<h<<endl;
10 l=lcd(u,v,h);
11 cout<<"L.C.D="<<l<<endl;
12 return 0;
13 }
14
15 int hcf(int u,int v)
16 {int t,r;
17 if (v>u)
18 {t=u;u=v;v=t;}
19 while ((r=u%v)!=0)
20 {u=v;
21 v=r;}
22 return(v);
23 }
24
25 int lcd(int u,int v,int h)
26 {return(u*v/h);
27 }
57 69
H.C.F=3
L.C.D=1311
Press any key to continue