The task was:
You’re given A/B and C/D. You will have to calculate A/B + C/D and answer it as E/F.
Input specification
On the first line you’re given the test case number N. Then there will be N line following. Each line consist of 4 integers with two “/” in the middle. For example: the each line will be “A/B C/D”.Output specification
For every test case, print out the sum of the given two fractions in the format: "numerator/denominator".
My code
#include <stdio.h>
int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
int main()
{
int T;
scanf("%d", &T);
for (int i=1; i<=T; i++)
{
int num1, den1;
int num2, den2;
scanf("%d%*c%d %d%*c%d", &num1,&den1,&num2,&den2);
int num3, den3;
den3 = gcd(den1,den2);
den3 = (den1*den2)/den3;
num3 = (num1)*(den3/den1) + (num2)*(den3/den2);
printf("Case %d: %d/%d\n", i, num3, den3);
}
return 0;
}