帮忙给指出错误及如何改正
分数计算器
#include"stdio.h"
#include"math.h"
int gys(int x,int y)
{
return y?gys(y,x%y):x;
}
int gbs(int x,int y)
{
return x*y/gys(x,y);
}
void yuefen(int x,int y)
{
int n;
n=gys(x,y);
x=x/n;
y=y/n;
printf("jie guo shi %d/%d",x,y);
}
void add(int a,int b,int c,int d)
{
int m,fx,fy,he;
m=gbs(b,d);
fx=a*m/b;
fy=c*m/d;
he=fx+fy;
yuefen(he,m);
}
void sub(int a,int b,int c,int d)
{
int m,fx,fy,he;
m=gbs(b,d);
fx=a*m/b;
fy=c*m/d;
yuefen(fx-fy,m);
}
void mul(int a,int b,int c,int d)
{
int m,n;
m=a*c;
n=b*d;
yuefen(m,n);
}
void div(int a,int b,int c,int d)
{
int m,n;
m=a*d;
n=b*c;
yuefen(m,n);
}
main()
{
char op;
int i,j,k,l;
printf("fenbieshurulianggefenshudefenzifenmu:");
scanf("%d,%d,%c,%d,%d",&i,&j,&op,&k,&l);
getchar();
switch(op)
{
case'+':add(i,j,k,l);
break;
case'-':sub(i,j,k,l);
break;
case'*':mul(i,j,k,l);
break;
case'/':div(i,j,k,l);
break;
}
getchar();
}
不知为什么带入数,出现混乱数字