Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Project1;
- uses
- System.SysUtils;
- Function InputData (Min : Integer; Max : Integer): Integer;
- Var
- N : Integer;
- IsCorrect : Boolean;
- Begin
- N := 0;
- Repeat
- IsCorrect := True;
- Try
- Readln(N);
- Except
- Writeln ('Please, enter a positive integer number:');
- IsCorrect := False;
- End;
- If (IsCorrect And ((N < Min) Or (N > Max))) Then
- Begin
- Writeln('Please, enter a positive number:');
- IsCorrect := False;
- End;
- Until (IsCorrect) ;
- InputData := N;
- End;
- Function EnterArraySize () : Integer;
- Const
- Min = 1;
- Max = 10;
- Begin
- Writeln ('Input number of digits: ');
- EnterArraySize := InputData (Min, Max);
- End;
- Type
- TVector = Array of Integer;
- Function InputArray (N : Integer) : TVector;
- Var
- Arr : TVector;
- Const
- Min = 1;
- Max = 9;
- Begin
- Writeln ('Enter the numbers one by one: ');
- SetLength(Arr, N);
- Dec (N);
- For var I := 0 to N do
- Begin
- Arr[I] := InputData (Min, Max);
- End;
- InputArray := Arr;
- End;
- Function ArrayToInt (N : Integer; Arr : TVector) : Integer;
- Var
- C : Integer;
- Begin
- C := 0;
- Dec (N);
- For var I := 0 to N do
- C := C * 10 + Arr[I];
- ArrayToInt := C;
- End;
- Procedure Divide (Number1 : Real; Number2 : Real);
- Var
- Number : Real;
- DecimalPlaces, NumberForLoopVirgin, K, N, NumberInt: Integer;
- Arr : TVector;
- IsCorrect : Boolean;
- Const
- Min = 0;
- Max = 7;
- Begin
- K := 0;
- Number := Number1 / Number2;
- NumberForLoopVirgin := Trunc (Number);
- If (NumberForLoopVirgin = 0) then
- K := 0
- Else
- While (NumberForLoopVirgin > 0) Do
- Begin
- NumberForLoopVirgin := NumberForLoopVirgin div 10;
- Inc (K);
- End;
- Writeln ('How many decimal places do you want to output? (<8):');
- DecimalPlaces := InputData (Min, Max);
- For var I := 0 to DecimalPlaces - 1 do
- Number := Number * 10;
- N := DecimalPlaces + K;
- SetLength (Arr, N);
- NumberInt := Trunc (Number);
- Dec (N);
- For var I := 0 to N do
- Begin
- Arr[I] := (NumberInt Mod 10);
- Number := Number / 10;
- NumberInt := Trunc (Number);
- End;
- Writeln ('Result is: ');
- If (K = 0) Then
- Writeln ('0');
- For var I := N DownTo DecimalPlaces Do
- Writeln (Arr[I]);
- If (DecimalPlaces > 0 )Then
- Begin
- Writeln (',');
- For Var I := DecimalPlaces - 1 DownTo 0 Do
- Writeln (Arr[I]);
- End;
- End;
- Var
- Size1, Size2: Integer;
- Arr1, Arr2 : TVector;
- Number1, Number2 : Real;
- Begin
- Size1 := EnterArraySize ();
- Arr1 := InputArray (Size1);
- Number1 := ArrayToInt (Size1, Arr1);
- Size2 := EnterArraySize ();
- Arr2 := InputArray (Size2);
- Number2 := ArrayToInt (Size2, Arr2);
- Divide (Number1, Number2);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement