Advertisement
klasscho

Untitled

Oct 30th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. Program Project6;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. sysUtils;
  7. function CheckOne(max : integer) : integer;
  8. var
  9. IsCorrect: Boolean;
  10. input: integer;
  11. begin
  12. repeat
  13. try
  14. readln(input);
  15. if ((input > 0) and (input < max)) then
  16. IsCorrect := True
  17. else
  18. writeln('Enter a correct value!');
  19. except
  20. IsCorrect := False;
  21. writeln ('Try again. Enter a correct value!');
  22. end;
  23. until IsCorrect;
  24. CheckOne := input;
  25. end;
  26. procedure CheckTwo(var num, den : integer);
  27. var
  28. l, min : integer;
  29. begin
  30. if den > num then min := den else min := num;
  31. for l := 1 to min do
  32. if (num mod l = 0) and (den mod l = 0) then
  33. begin
  34. num := num div l;
  35. den := den div l;
  36. end;
  37. end;
  38.  
  39. function fraction(num, den: integer) : integer;
  40. var
  41. mult: integer;
  42. begin
  43. mult := num * den;
  44. fraction := mult;
  45. end;
  46. const
  47. MaxInt = 46340;
  48. var
  49. m, n, p, q, a, b, num1, den1 : integer;
  50. begin
  51. Writeln ('This program divides two irreducible fractions');
  52. writeln('Enter the value of the first numerator : ');
  53. m := CheckOne(MaxInt);
  54. writeln('Enter the value of the first denominator : ');
  55. n := CheckOne(MaxInt);
  56. writeln('Enter the value of the second numerator : ');
  57. p := CheckOne(MaxInt);
  58. writeln('Enter the value of the second denominator : ');
  59. q := CheckOne(MaxInt);
  60. CheckTwo(m, q);
  61. CheckTwo(p, n);
  62. num1 := fraction(m, p);
  63. den1 := fraction(n, q);
  64. writeln (num1 ,'/', den1);
  65. readln;
  66. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement