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

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 <bits/stdc++.h> ` `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; ` `} ` |

*chevron_right*

*filter_none*

## 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) ` |

*chevron_right*

*filter_none*

## 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) ` |

*chevron_right*

*filter_none*

## 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) ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Program to find deltaX ` ` ` `// function to find delta X ` `function` `findDelta(` `$a` `, ` `$b` `, ` ` ` `$c` `, ` `$d` `) ` `{ ` ` ` `return` `(` `$b` `* ` `$c` `- ` ` ` `$a` `* ` `$d` `) / (` `$d` `- ` `$c` `); ` `} ` ` ` `// Driver Code ` `$a` `= 3; ` `$b` `= 9; ` `$c` `= 3; ` `$d` `= 5; ` ` ` `// u0394X is code for delta sign ` `echo` `"?X = "` `.findDelta(` `$a` `, ` `$b` `, ` ` ` `$c` `, ` `$d` `); ` ` ` `// This code is contributed by ` `// Manish Shaw(manishshaw1) ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

ΔX = 6

## Recommended Posts:

- Largest proper fraction with sum of numerator and denominator equal to a given number
- Convert Binary fraction to Decimal
- Convert decimal fraction to binary number
- Find Recurring Sequence in a Fraction
- Fraction
- First occurrence of a digit in a given fraction
- Fraction module in Python
- Reduce the fraction to its lowest form
- Greedy Algorithm for Egyptian Fraction
- as_integer_ratio() in Python for reduced fraction of a given rational
- Maximum rational number (or fraction) from an array
- Expressing a fraction as a natural number under modulo 'm'
- Represent the fraction of two numbers in the string format
- Print first N terms of series (0.25, 0.5, 0.75, ...) in fraction representation
- Find the integers that doesnot ends with T1 or T2 when squared and added X

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.