比较两个分数的大小
流程图:
伪代码:
源代码:
#include<iostream>
using namespace std;
int main(){
int a1,a2,b1,b2,c1,c2,d1,d2,i;
cout<<"输入要比较的两个分数"<<endl;
cin>>a1;
getchar();
cin>>a2;
cin>>b1;
getchar();
cin>>b2;
if(a2>b2){
int t1,t2;
t1=b2;
b2=a2;
a2=t1;
t2=b1;
b1=a1;
a1=t2;
}
for(i=b2;;i++){
if(i%a2==0&&i%b2==0){
c2=i;
d2=i;
c1=a1*(i/a2);
d1=b1*(i/b2);
break;
}
}
if(c1>d1){
cout<<a1<<"/"<<a2<<" > "<<b1<<"/"<<b2<<endl;
}
else{
cout<<a1<<"/"<<a2<<" < "<<b1<<"/"<<b2<<endl;
}
return 0;
}
标签:cout,37,cin,c++,a1,a2,b1,b2,打卡 From: https://www.cnblogs.com/HD-Kudu-2219/p/17426169.html