Advertisement
klasscho

Untitled

Oct 31st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 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 = den;
  23. }
  24. else
  25. min = num;
  26. for (int l = 0; l < min;)
  27. do {
  28. if (( int num % l = 0) && (int den % l = 0))
  29. num = num / l;
  30. den = den / l;
  31. }
  32. }
  33. int fraction (int num, int den)
  34. {
  35. int mult;
  36. mult = num * den;
  37. return mult;
  38. }
  39. void main()
  40. {
  41. const int MaxInt = 46340;
  42. int m, n, p, q, a, b, num1, den1;
  43. cout << "This program divides two irreducible fractions";
  44. cout << "Enter the value of the first numerator :";
  45. CheckOne(m);
  46. cout << "\nEnter the value of the first denominator :\n";
  47. CheckOne(n);
  48. cout << "\nEnter the value of the second numerator :\n";
  49. CheckOne(p);
  50. cout << "\nEnter the value of the second denominator :\n";
  51. CheckOne(q);
  52. CheckTwo(m, p);
  53. CheckTwo(n, q);
  54. num1 = fraction(m, p);
  55. den1 = fraction(n, q);
  56. cout << "Received fraction :" << num1 << " / " << den1;
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement