Advertisement
Vladislav8653

laba_2_2_delphi

Nov 8th, 2022 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.03 KB | None | 0 0
  1. Program Project1;
  2. uses
  3.   System.SysUtils;
  4.  
  5. Function InputData (Min : Integer; Max : Integer): Integer;
  6. Var
  7.     N : Integer;
  8.     IsCorrect : Boolean;
  9. Begin
  10.     N := 0;
  11.     Repeat
  12.         IsCorrect := True;
  13.         Try
  14.             Readln(N);
  15.         Except
  16.             Writeln ('Please, enter a positive integer number:');
  17.             IsCorrect := False;
  18.         End;
  19.         If (IsCorrect And ((N < Min) Or (N > Max))) Then
  20.         Begin
  21.             Writeln('Please, enter a positive number:');
  22.             IsCorrect := False;
  23.         End;
  24.     Until (IsCorrect) ;
  25.     InputData := N;
  26. End;
  27.  
  28. Function EnterArraySize () : Integer;
  29. Const
  30.     Min = 1;
  31.     Max = 10;
  32. Begin
  33.     Writeln ('Input number of digits: ');
  34.     EnterArraySize := InputData (Min, Max);
  35. End;
  36.  
  37. Type
  38.     TVector = Array of Integer;
  39.  
  40. Function InputArray (N : Integer) : TVector;
  41. Var
  42.     Arr : TVector;
  43. Const
  44.     Min = 1;
  45.     Max = 9;
  46. Begin
  47.     Writeln ('Enter the numbers one by one: ');
  48.     SetLength(Arr, N);
  49.     Dec (N);
  50.     For var I := 0 to N do
  51.         Begin
  52.             Arr[I] := InputData (Min, Max);
  53.         End;
  54.     InputArray := Arr;
  55. End;
  56.  
  57. Function ArrayToInt (N : Integer; Arr : TVector) : Integer;
  58. Var
  59.     C : Integer;
  60. Begin
  61.     C := 0;
  62.     Dec (N);
  63.     For var I := 0 to N do
  64.         C := C * 10 + Arr[I];
  65.     ArrayToInt := C;
  66. End;
  67.  
  68. Procedure Divide (Number1 : Real; Number2 : Real);
  69. Var
  70.     Number : Real;
  71.     DecimalPlaces, NumberForLoopVirgin, K, N, NumberInt: Integer;
  72.     Arr : TVector;
  73.     IsCorrect : Boolean;
  74. Const
  75.     Min = 0;
  76.     Max = 7;
  77. Begin
  78.     K := 0;
  79.     Number := Number1 / Number2;
  80.     NumberForLoopVirgin := Trunc (Number);
  81.     If (NumberForLoopVirgin = 0) then
  82.         K := 0
  83.     Else
  84.         While (NumberForLoopVirgin > 0) Do
  85.             Begin
  86.                 NumberForLoopVirgin := NumberForLoopVirgin div 10;
  87.                 Inc (K);
  88.             End;
  89.     Writeln ('How many decimal places do you want to output? (<8):');
  90.     DecimalPlaces := InputData (Min, Max);
  91.     For var I := 0 to DecimalPlaces - 1 do
  92.         Number := Number * 10;
  93.     N := DecimalPlaces + K;
  94.     SetLength (Arr, N);
  95.     NumberInt := Trunc (Number);
  96.     Dec (N);
  97.     For var I := 0 to N do
  98.         Begin
  99.             Arr[I] := (NumberInt Mod 10);
  100.             Number := Number / 10;
  101.             NumberInt := Trunc (Number);
  102.         End;
  103.     Writeln ('Result is: ');
  104.     If (K = 0) Then
  105.         Writeln ('0');
  106.     For var I := N DownTo DecimalPlaces Do
  107.         Writeln (Arr[I]);
  108.     If (DecimalPlaces > 0 )Then
  109.         Begin
  110.             Writeln (',');
  111.             For Var I := DecimalPlaces - 1 DownTo 0 Do
  112.                 Writeln (Arr[I]);
  113.         End;
  114. End;
  115.  
  116. Var
  117.     Size1, Size2: Integer;
  118.     Arr1, Arr2 : TVector;
  119.     Number1, Number2 : Real;
  120. Begin
  121.     Size1 := EnterArraySize ();
  122.     Arr1 := InputArray (Size1);
  123.     Number1 := ArrayToInt (Size1, Arr1);
  124.     Size2 := EnterArraySize ();
  125.     Arr2 := InputArray (Size2);
  126.     Number2 := ArrayToInt (Size2, Arr2);
  127.     Divide (Number1, Number2);
  128.     Readln;
  129. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement