求一个真分数的埃及分数表示
埃及分数是指只使用1作为分子的分数,例如8/11=1/2+1/5+1/55+1/110;
流程图:
伪代码:
源代码:
#include<iostream>
using namespace std;
int main(){
int a,b,c,i,j;
cout<<"请输入一个真分数"<<endl;
cin>>a;
getchar();
cin>>b;
if(a>b){
cout<<"你写的不是真分数"<<endl;
}
if(b%a==0){
cout<<"1/"<<b/a<<endl;
}
else{
while(1){
c=b/a+1;
a=a*c-b;
b=b*c;
cout<<"1/"<<c<<"+";
if(a==3&&b%2==0){
cout<<"1/"<<b/2<<"+1/"<<b;
break;
}
}
}
return 0;
}
标签:分数,b%,cout,33,c++,int,打卡 From: https://www.cnblogs.com/HD-Kudu-2219/p/17413181.html