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


In this article, we will be discussing a program to find ΔX which is added to the numerator and denominator both of given fraction (a/b) to convert it to another given irreducible fraction (c/d).

For example, let us suppose we have been given with the following values,

a = 4 | b = 2 | c = 4 | d = 3

then ΔX would be 4 such that (a + ΔX)/(b + ΔX) = 8/6 = 2/3

As we know, (a + ΔX)/(b + ΔX) = c/d. Solving this equation for ΔX, we get

ΔX = (bc - ad) / (d - c)

Example

 Live Demo

#include <iostream>
using namespace std;
int main() {
   int a = 4;
   int b = 2;
   int c = 4;
   int d = 3;
   int dif = 0;
   dif = (b*c-a*d)/(d-c);
   cout << "The value of \u0394x :" << endl;
   cout << dif << endl;
   return 0;
}

Output

The value of Δx :
4

Updated on: 03-Oct-2019

40 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements