Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

You are given four numbers **num1, den1, num2, and den2**. You need to find** (num1/den1)+(num2/den2) **and output the result in the form of **(numx/denx)**.

**Input Format:**

The first line of input contains an integer **T** denoting the number of test cases . Then T test cases follow . Each test case contains four integers **num1, den1, num2, den2 **respectively .

**Output Format:**

For each test case, in a new line, output will be the fraction in the form** a/b** where the fraction denotes the sum of the two given fractions in reduced form.

**Your Task:**

Since this is a function problem, you don't need to worry about the testcases. Your task is to complete the function **addFraction ** which adds the two fractions and prints the resulting fraction. The function takes four arguments **num1, den1, num2, den2 **where **num1, num2 **denotes the **numerators **of two fractions and **den1, den2 **denotes their **denominators**.

**Constraints:**

1 <= T <= 100

1 <= den1,den2,num1,num2 <= 1000

**Example:
Input**

1

1 500 2 500

3/500

**Explanation:**

In above test case 1/500+2/500=3/500

**Note:**The **Input/Ouput** format and **Example** given are used for system's internal purpose, and should be used by a user for **Expected Output** only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Add two fractions

...

Here is some troubleshooting advice:

- Reset the IDE using the second button on the top right corner.
- Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
- Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
- You can access the hints to get an idea about what is expected of you as well as the final solution code.
- You can view the solutions submitted by other users from the submission tab.

Here is some troubleshooting advice for contest problems

- Make sure you are not using ad-blockers.
- Disable browser extensions.
- We recommend using latest version of your browser for best experience.
- Avoid using static/global variables in coding problems as your code is tested against multiple test cases and these tend to retain their previous values.
- Passing the Sample/Custom Test cases in coding problems does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.