Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program laba_2_2;
- uses
- System.SysUtils;
- function enter(Min, Max : Integer): Byte;
- var
- Temp : Integer;
- Iscorrect : Boolean;
- begin
- repeat
- try
- Read(Temp);
- if (Temp > Max) or (Temp < Min) then
- begin
- IsCorrect := False;
- WriteLn('This is a mistake. Please enter again!');
- end
- else
- IsCorrect := True
- except
- WriteLn('This is a mistake. Please enter again!');
- IsCorrect:=False;
- end;
- until(IsCorrect) ;
- result := Temp;
- end;
- function transfer(J, N, Num : Integer) : Integer;
- var
- Res, Temp, I : Integer;
- begin
- Res := 0;
- Temp := 1;
- N := N - 1;
- for I := J to N do
- Temp := Temp * 10;
- Res := Res + (Num * Temp);
- result := Res;
- end;
- function subtraction(J, N, Num : Integer) : Integer;
- var
- Res, Temp, I : Integer;
- begin
- Res := 0;
- Temp := 1;
- N := N - 1;
- Temp := Temp * 10;
- Res := Res + (Num mod Temp);
- result := Res;
- end;
- var I, N, Num1, Num2 : Integer;
- Numb1 : array [0..10] of Integer;
- Numb2 : array [0..10] of Integer;
- Res : array [0..10] of Integer;
- begin
- WriteLn('Enter the number of numb (n > 0 and n < 10)');
- N := enter(0,10);
- N := N - 1;
- for I := 0 to N do
- begin
- WriteLn('Enter the ', (I + 1), ' digit of the first number(digit > 0 and digit < 10)');
- Numb1[I] := enter(0, 10);
- end;
- for I := 0 to N do
- begin
- WriteLn('Enter the ', (I + 1), ' digit of the second number(digit > 0 and digit < 10)');
- Numb2[I] := enter(0,10);
- end;
- for I := N downto 0 do
- begin
- Num1 := Num1 + transfer(I, N, Numb1[I]);
- Num2 := Num2 + transfer(I, N, Numb2[I]);
- end;
- Num1 := Num1 - Num2;
- if Num1 < 0 then
- begin
- Num1 := abs(Num1);
- for I := N downto 0 do
- begin
- Res[I] := subtraction(I, N, Num1);
- Num1 := Num1 div 10;
- end;
- Res[0] := Res[0] * (-1);
- end
- else
- begin
- for I := N downto 0 do
- begin
- Res[I] := subtraction(I, N, Num1);
- Num1 := Num1 div 10;
- end;
- end;
- for I := 0 to N do
- Write(Res[I]);
- ReadLn;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement