# Untitled

unknown
plain_text
a year ago
1.7 kB
1
Indexable
Never
```#include <stdio.h>
#include <math.h>

typedef struct{
int p;
int q;
}rational;

int main()
{
rational num1;
scanf("%d", &num1.p);
scanf("%d", &num1.q);

rational num2;
scanf("%d", &num2.p);
scanf("%d", &num2.q);

printf("num1 is %d/%d\n", num1.p, num1.q);
printf("num2 is %d/%d\n", num2.p, num2.q);

mult(num1.p,num1.q,num2.p,num2.q);
sub(num1.p,num1.q,num2.p,num2.q);
dev(num1.p,num1.q,num2.p,num2.q);

}
int dem(int num1, int num2)
{
int x;
//no = nominator, dem = denominatior
if(num1 > num2 && num1 % num2 == 0){
x = num1;
}else if(num2 > num1 && num2 % num1 == 0){
x = num2;
}else{
x = num1 * num2;
}
return x;
}

int add(int num1p, int num1q,int num2p, int num2q)
{
int d = dem(num1q,num2q);
int sum_no = ((d/num1q)*num1p) + ((d/num2q)*num2p);
printf("sum is %d/%d\n", sum_no, d);

}

int sub(int num1p,int num1q,int num2p, int num2q)
{
int d = dem(num1q,num2q);
int sub_no = ((d/num1q)*num1p) - ((d/num2q)*num2p);
printf("subtraction is %d/%d\n", sub_no, d);

if(sub_no == 0){
printf("equal\n");
}else{
printf("not equal\n");
}
}

int mult(int num1p, int num1q,int num2p,int num2q)
{
int multi_no = (num1p*num2p);
int multi_dem = (num1q*num2q);
printf("multi is %d/%d\n", multi_no, multi_dem);
}

int dev(int num1p,int num1q,int num2p, int num2q)
{
int dev_no = (num1p*num2q);
int dev_dem = (num1q*num2p);

printf("division is %d/%d\n", dev_no, dev_dem);
}

```