Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Project6;
- {$APPTYPE CONSOLE}
- uses
- sysUtils;
- function CheckOne(max : integer) : integer;
- var
- IsCorrect: Boolean;
- input: integer;
- begin
- repeat
- try
- readln(input);
- if ((input > 0) and (input < max)) then
- IsCorrect := True
- else
- writeln('Enter a correct value!');
- except
- IsCorrect := False;
- writeln ('Try again. Enter a correct value!');
- end;
- until IsCorrect;
- CheckOne := input;
- end;
- procedure CheckTwo(var num, den : integer);
- var
- l, min : integer;
- begin
- if den > num then min := den else min := num;
- for l := 1 to min do
- if (num mod l = 0) and (den mod l = 0) then
- begin
- num := num div l;
- den := den div l;
- end;
- end;
- function fraction(num, den: integer) : integer;
- var
- mult: integer;
- begin
- mult := num * den;
- fraction := mult;
- end;
- const
- MaxInt = 46340;
- var
- m, n, p, q, a, b, num1, den1 : integer;
- begin
- Writeln ('This program divides two irreducible fractions');
- writeln('Enter the value of the first numerator : ');
- m := CheckOne(MaxInt);
- writeln('Enter the value of the first denominator : ');
- n := CheckOne(MaxInt);
- writeln('Enter the value of the second numerator : ');
- p := CheckOne(MaxInt);
- writeln('Enter the value of the second denominator : ');
- q := CheckOne(MaxInt);
- CheckTwo(m, q);
- CheckTwo(p, n);
- num1 := fraction(m, p);
- den1 := fraction(n, q);
- writeln (num1 ,'/', den1);
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement