Advertisement
klasscho

Untitled

Nov 1st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int CheckOne(int Max)
  4. {
  5. bool IsInCorrect;
  6. int InPut;
  7. do {
  8. cin >> InPut;
  9. if ((InPut < 0) && (InPut > Max))
  10. cout << "\nEnter a correct value!\n";
  11. else
  12. IsInCorrect = false;
  13. } while (IsInCorrect);
  14. return InPut;
  15. }
  16.  
  17. void CheckTwo(int& num, int& den)
  18. {
  19. int l;
  20. int min;
  21. if (den > num) {
  22. min = num;
  23. }
  24. else {
  25. min = den;
  26. }
  27. for (int l = 2; l < min; l++) {
  28. if ( num % l == 0 && den % l == 0) {
  29. num = num / l;
  30. den = den / l;
  31. }
  32. }
  33. }
  34.  
  35. int fraction(int num, int den)
  36. {
  37. int mult;
  38. mult = num * den;
  39. return mult;
  40. }
  41.  
  42. int main()
  43. {
  44. const int MaxInt = 46340;
  45. int m, n, p, q, a, b, num1, den1;
  46. cout << "\nThis program divides two irreducible fractions\n";
  47. cout << "\nEnter the value of the first numerator :\n";
  48. m = CheckOne(MaxInt);
  49. cout << "\nEnter the value of the first denominator :\n";
  50. n = CheckOne(MaxInt);
  51. cout << "\nEnter the value of the second numerator :\n";
  52. p = CheckOne(MaxInt);
  53. cout << "\nEnter the value of the second denominator :\n";
  54. q = CheckOne(MaxInt);
  55. CheckTwo(m, p);
  56. CheckTwo(n, q);
  57. num1 = fraction(m, p);
  58. den1 = fraction(n, q);
  59. cout << "Received fraction : " << num1 << " / " << den1;
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement