自己做老是错的·帮帮忙
发布网友
发布时间:2023-08-02 12:57
我来回答
共2个回答
热心网友
时间:2023-09-19 16:29
#include <stdio.h>
void menu(int *a, int *b, int *c, int *d, char *op);
void addFractions(int a, int b, int c, int d, int *e, int *f);
void subFractions(int a, int b, int c, int d, int *e, int *f);
void mulFractions(int a, int b, int c, int d, int *e, int *f);
void divFractions(int a, int b, int c, int d, int *e, int *f);
void simFractions(int a, int b);
int *(int a, int b);/* greatest common divisor */
int lcm(int a, int b);/* least common multiple */
void main()
{
int a,b,c,d,e,f;/* a/b and c/d, b!=0, d!=0 */
char op; /* (+,-,*,/) */
menu(&a,&b,&c,&d,&op);
printf("\n%d/%d%c%d/%d", a, b, op, c, d);
switch(op)
{
case '+':addFractions(a,b,c,d,&e,&f);break;
case '-':subFractions(a,b,c,d,&e,&f);break;
case '*':mulFractions(a,b,c,d,&e,&f);break;
case '/':divFractions(a,b,c,d,&e,&f);break;
default:break;
}
simFractions(e,f);
getch();
}
void menu(int *a, int *b, int *c, int *d, char *op)
{
while(1)
{
printf("Please input 4 integers 'a/b,c/d':");
if(scanf("%d/%d,%d/%d", a, b, c, d) && (*b)*(*d) != 0) break;
}
while(1)
{
printf("Please select an operation(+ - * /):");
*op=getch();
if(*op == '+' || *op == '-' || *op == '*' || *op == '/') break;
}
}
void addFractions(int a, int b, int c, int d, int *e, int *f)
{
*e = a*d+c*b;
*f = b*d;
}
void subFractions(int a, int b, int c, int d, int *e, int *f)
{
*e = a*d - c*b;
*f = b*d;
}
void mulFractions(int a, int b, int c, int d, int *e, int *f)
{
*e = a*c;
*f = b*d;
}
void divFractions(int a, int b, int c, int d, int *e, int *f)
{
*e = a*d;
*f = b*c;
}
void simFractions(int a, int b)
{
int t;
if (a==0)
{
printf(" = 0.0\n");
return;
}
t = *(a,b);
if(t!=1)
{
printf(" = %d/%d", a, b);
}
a = a/t;
b = b/t;
printf(" = %d/%d = %f\n", a, b, (float)a/b );
return;
}
int *(int a, int b)
{
int t;
if(a<b) {t=a;a=b;b=t;}
while(a%b)
{
t=a%b;
a=b;
b=t;
}
return b;
}
int lcm(int a, int b)
{
return (a*b)/*(a,b);
}
热心网友
时间:2023-09-19 16:30
???!
呵呵,才疏学浅。和LZ一起期待答案