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

C++Server Side ProgrammingProgramming

In this tutorial, we are going to write a program that calculates ∆ X﻿ value that satisfies the given equation. The equation is (a + ∆ X)/(b + ∆ X) = c/d﻿.

Here, we need a little bit of math to solve the equation. And it's straightforward. Cross multiply and take ∆X to one side.

You will get the value of ∆X﻿ as (b*c-a*d)/(d-c).

We are given a, b, c, and d values. Finding \Delta XΔX﻿ value is straightforward.

## Example

Let's see the code.

Live Demo

#include <bits/stdc++.h>
using namespace std;
int findTheXValue(int a, int b, int c, int d) {
return (b * c - a * d) / (d - c);
}
int main() {
int a = 5, b = 2, c = 8, d = 7;
cout << findTheXValue(a, b, c, d) << endl;
return 0;
}

## Output

If you run the above code, then you will get the following result.

19

## Conclusion

If you have any queries in the tutorial, mention them in the comment section.

Published on 29-Dec-2020 10:54:00