Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program LABA_2_2;
- uses
- System.SysUtils;
- function Input(X :Integer): Integer;
- var
- L : Integer;
- IsCorrect : Boolean;
- Begin
- Repeat
- IsCorrect := True;
- Writeln('Введите');
- Try
- Readln(L);
- Except
- Writeln('Введите целое число!');
- IsCorrect := False;
- End;
- If (L = 0) and (X = 2) then
- Begin
- Writeln('Чило не должно быть равно 0');
- IsCorrect := False;
- End;
- Until (IsCorrect);
- Input :=L
- End;
- function FindNumerator(M, N, P, Q :Integer):Integer;
- var
- A: Integer;
- begin
- A := M * Q + P * N;
- FindNumerator := A;
- end;
- function FindDenumerator(N, Q :Integer):Integer;
- var
- B : Integer;
- begin
- B := N * Q;
- FindDenumerator := B;
- end;
- function ReduceFraction(C, D , X :Integer):Integer;
- begin
- repeat
- if C>D then
- C:=C-D
- else
- D:=D-C;
- until (D = C);
- if X = 1 then
- ReduceFraction := C;
- if X = 2 then
- ReduceFraction := D;
- end;
- procedure PrintFraction(A, B, C, D :Integer);
- begin
- writeln (A div C , '/', B div D);
- end;
- procedure Main();
- var
- A, B, C, D, M, N, P, Q :Integer;
- begin
- Writeln('Данная программа находит сумму двух несократимых дробей.');
- Writeln('Введите дроби');
- M := Input(1);
- N := Input(2);
- P := Input(1);
- Q := Input(2);
- A := FindNumerator(M, N, P, Q);
- B := FindDenumerator(N, Q);
- C := A;
- D := B;
- C := ReduceFraction(C, D, 1);
- D := ReduceFraction(C, D , 2);
- Writeln('Их сумма');
- PrintFraction(A, B, C, D);
- Readln;
- end;
- Begin
- Main();
- End.
Add Comment
Please, Sign In to add comment