求c++大神把下面的简单语句修改下,用cin,cout语句,替换printf的输入输出语句 20

#include<cstdio>#include<iostream>#include<cstring>#include<cmath>usingnamespacestd;c... #include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
char s[105];
int ff=0;
int geta1()
{
int i;
int y=0;
for(i=0; s[i]; i++)if(s[i]=='/')
{
ff=1;
break;
}
int x=1;
for(int j=1; j<=i; j++)
{
if(s[i-j]=='-')
{
y=-y;
break;
}
y+=(s[i-j]-'0')*x;
x*=10;
}
return y;
}
int geta2()
{
int i;
for(i=0; s[i]; i++)if(s[i]=='/')
{
break;
}
int len;
len= strlen(s);
int x=1, y=0;
for(int j=len-1; j>i; j--)
{
if(s[j]=='-')
{
y=-y;
break;
}
y+=(s[j]-'0')*x;
x*=10;
}
return y;
}
int gcd(int a, int b){
if(a<b)swap(a,b);
return b==0 ?a:gcd(b, a%b);
}
void jia(int a, int b, int c, int d)
{
int gy;
gy=gcd(b, d);
int gb;
gb=b*d/gy;
a=gb/b*a;
c=gb/d*c;
int x, y;
x=a+c;
y=gb;
gy=gcd(abs(x), abs(y));
x/=gy;
y/=gy;
printf("答案:");
if(y!=1) printf("%d/%d\n", x, y);
else printf("%d\n", x);
}
void jian(int a, int b, int c, int d)
{
int gy;
gy=gcd(b, d);
int gb;
gb=b*d/gy;
a=gb/b*a;
c=gb/d*c;
int x, y;
x=a-c;
y=gb;
gy=gcd(abs(x), abs(y));
x/=gy;
y/=gy;
printf("答案:");
if(y!=1) printf("%d/%d\n", x, y);
else printf("%d\n", x);
}
void chen(int a, int b, int c, int d)
{
int gy;
gy=gcd(b, d);
int gb;
gb=b*d/gy;
a=gb/b*a;
c=gb/d*c;
int x, y;
x=a*c;
y=gb*gb;
gy=gcd(abs(x), abs(y));
x/=gy;
y/=gy;
printf("答案:");
if(y!=1) printf("%d/%d\n", x, y);
else printf("%d\n", x);
展开
 我来答
匿名用户
2016-06-26
展开全部
printf("%d/%d\n", x, y); →cout<<x/y\n ;
printf("%d\n", x);→cout<<x\n;
printf("答案:");→cout<<"答案:";
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
chiconysun
2016-06-26 · TA获得超过2.2万个赞
知道大有可为答主
回答量:5410
采纳率:92%
帮助的人:2725万
展开全部
按题目中粘贴的代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
char s[105];
int ff=0;
int geta1()
{
int i;
int y=0;
for(i=0; s[i]; i++)if(s[i]=='/')
{
ff=1;
break;
}
int x=1;
for(int j=1; j<=i; j++)
{
if(s[i-j]=='-')
{
y=-y;
break;
}
y+=(s[i-j]-'0')*x;
x*=10;
}
return y;
}
int geta2()
{
int i;
for(i=0; s[i]; i++)if(s[i]=='/')
{
break;
}
int len;
len= strlen(s);
int x=1, y=0;
for(int j=len-1; j>i; j--)
{
if(s[j]=='-')
{
y=-y;
break;
}
y+=(s[j]-'0')*x;
x*=10;
}
return y;
}
int gcd(int a, int b){
if(a<b)swap(a,b);
return b==0 ?a:gcd(b, a%b);
}
void jia(int a, int b, int c, int d)
{
int gy;
gy=gcd(b, d);
int gb;
gb=b*d/gy;
a=gb/b*a;
c=gb/d*c;
int x, y;
x=a+c;
y=gb;
gy=gcd(abs(x), abs(y));
x/=gy;
y/=gy;
cout << "答案:";
if(y!=1) cout << x << "/" << y << endl;
else cout << x << endl;
}
void jian(int a, int b, int c, int d)
{
int gy;
gy=gcd(b, d);
int gb;
gb=b*d/gy;
a=gb/b*a;
c=gb/d*c;
int x, y;
x=a-c;
y=gb;
gy=gcd(abs(x), abs(y));
x/=gy;
y/=gy;
cout << "答案:";
if(y!=1) cout << x << "/" << y << endl;
else cout << x << endl;
}
void chen(int a, int b, int c, int d)
{
int gy;
gy=gcd(b, d);
int gb;
gb=b*d/gy;
a=gb/b*a;
c=gb/d*c;
int x, y;
x=a*c;
y=gb*gb;
gy=gcd(abs(x), abs(y));
x/=gy;
y/=gy;
cout << "答案:";
if(y!=1) cout << x << "/" << y << endl;
else cout << x << endl;
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式