# Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)

• Last Updated : 14 Jun, 2022

Given a fraction in form of a/b where a & b are positive integers. Find ΔX such that when it is added to numerator as well as denominator of given fraction it will result into a new Ir-reducible fraction c/d.
Examples:

```Input : a = 4, b = 10, c = 1, d = 2
Output : ΔX = 2
Explanation : (a + ΔX)/(b + ΔX) =
(4 + 2) / (10 + 2) = 6/12 = 1/2 = c/d

Input : a = 4, b = 10, c = 2, d = 5
Output : ΔX = 0
Explanation : (a + ΔX) / (b + ΔX) =
(4) / (10) = 2 / 5 = c/d```

To solve this type of problem rather than implementing just a programming approach we have to do a little of mathematics. mathematics just necessary is as:

```As per question we have to find ΔX such that:
=> (a + ΔX) / (b + ΔX) = c / d
=> ad + dΔX = bc + cΔX
=> dΔX - cΔX = bc - ad
=> ΔX (d - c) = bc -ad
=> ΔX = (bc - ad) / (d - c)```

So, in a way to finding ΔX we have to only calculate ## C++

 `// C++ Program to find deltaX``#include ``using` `namespace` `std;` `// function to find delta X``int` `findDelta(``int` `a, ``int` `b, ``int` `c, ``int` `d)``{``    ``return` `(b * c - a * d) / (d - c);``}` `// driver program``int` `main()``{``    ``int` `a = 3, b = 9, c = 3, d = 5;` `    ``// u0394X is code for delta sign``    ``cout << ``"\u0394X = "` `<< findDelta(a, b, c, d);``    ``return` `0;``}`

## Java

 `// Java Program to``// find deltaX``import` `java.io.*;` `class` `GFG``{``    ``// function to find delta X``    ``static` `int` `findDelta(``int` `a, ``int` `b,``                         ``int` `c, ``int` `d)``    ``{``        ``return` `(b * c - a *``                ``d) / (d - c);``    ``}``    ` `    ``// Driver Code``    ``public` `static` `void` `main(String args[])``    ``{``        ``int` `a = ``3``, b = ``9``,``            ``c = ``3``, d = ``5``;``    ` `        ``// u0394X is code``        ``// for delta sign``        ``System.out.print(``"\u0394X = "` `+``                ``findDelta(a, b, c, d));``    ``}``}` `// This code is contributed``// by Manish Shaw(manishshaw1)`

## Python3

 `# Python Program to find deltaX``# !/usr/bin/python``# coding=utf-8` `# function to find delta X``def` `findDelta(a, b, c, d) :` `    ``return` `int``((b ``*` `c ``-``                ``a ``*` `d) ``/``               ``(d ``-` `c));` `# Driver Code``a ``=` `3``; b ``=` `9``;``c ``=` `3``; d ``=` `5``;` `# u0394X is code``# for delta sign``print` `(``"X = {}"` `.``        ``format``(findDelta(a, b,``                         ``c, d)));` `# This code is contributed by``# Manish Shaw(manishshaw1)`

## C#

 `// C# Program to``// find deltaX``using` `System;` `class` `GFG``{``// function to find delta X``static` `int` `findDelta(``int` `a, ``int` `b,``                     ``int` `c, ``int` `d)``{``    ``return` `(b * c - a *``            ``d) / (d - c);``}` `// Driver Code``static` `void` `Main()``{``    ``int` `a = 3, b = 9,``        ``c = 3, d = 5;` `    ``// u0394X is code``    ``// for delta sign``    ``Console.Write(``"\u0394X = "` `+``                  ``findDelta(a, b, c, d));``}``}` `// This code is contributed``// by Manish Shaw(manishshaw1)`

## PHP

 ``

## Javascript

 ``

Output:

`ΔX = 6`

Time Complexity: O(1)
Auxiliary Space: O(1)

My Personal Notes arrow_drop_up