
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d) in C++
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.
#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.
Advertisements