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 = den;
- }
- else
- min = num;
- for (int l = 0; l < min;)
- do {
- if (( int num % l = 0) && (int den % l = 0))
- num = num / l;
- den = den / l;
- }
- }
- int fraction (int num, int den)
- {
- int mult;
- mult = num * den;
- return mult;
- }
- void main()
- {
- const int MaxInt = 46340;
- int m, n, p, q, a, b, num1, den1;
- cout << "This program divides two irreducible fractions";
- cout << "Enter the value of the first numerator :";
- CheckOne(m);
- cout << "\nEnter the value of the first denominator :\n";
- CheckOne(n);
- cout << "\nEnter the value of the second numerator :\n";
- CheckOne(p);
- cout << "\nEnter the value of the second denominator :\n";
- CheckOne(q);
- 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