Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int CheckOne(int Max)
- {
- bool IsInCorrect;
- int InPut;
- do {
- cin >> InPut;
- if ((InPut < 0) && (InPut > Max))
- cout << "\nEnter a correct value!\n";
- else
- IsInCorrect = false;
- } while (IsInCorrect);
- return InPut;
- }
- void CheckTwo(int& num, int& den)
- {
- int l;
- int min;
- if (den > num) {
- min = num;
- }
- else {
- min = den;
- }
- for (int l = 2; l < min; l++) {
- if ( num % l == 0 && den % l == 0) {
- num = num / l;
- den = den / l;
- }
- }
- }
- int fraction(int num, int den)
- {
- int mult;
- mult = num * den;
- return mult;
- }
- int main()
- {
- const int MaxInt = 46340;
- int m, n, p, q, a, b, num1, den1;
- cout << "\nThis program divides two irreducible fractions\n";
- cout << "\nEnter the value of the first numerator :\n";
- m = CheckOne(MaxInt);
- cout << "\nEnter the value of the first denominator :\n";
- n = CheckOne(MaxInt);
- cout << "\nEnter the value of the second numerator :\n";
- p = CheckOne(MaxInt);
- cout << "\nEnter the value of the second denominator :\n";
- q = CheckOne(MaxInt);
- CheckTwo(m, p);
- CheckTwo(n, q);
- num1 = fraction(m, p);
- den1 = fraction(n, q);
- cout << "Received fraction : " << num1 << " / " << den1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement