亲密数上传附件了,分数化简的用了辗转相除求最大公约数来化简。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include
using namespace std;
int gcd(int x,int y)
//欧几里得辗转相除法求两数的最大的公约数
{
int m;
if(x
if(x%y!=0)
return gcd(y,x%y);
else return y;
}
int main()
{
int a,b,k;
cout<<" 请输入分子和分母,空格键间隔 "<
if(a*b<0)
cout<<"-";
a=int(abs(a));
b=int(abs(b));
k=gcd(a,b);
cout<//system("pause");
}