with Ada.Numerics.Elementary_Functions; with Ada.Text_IO; with Ada.Float_Text_IO; with Ada.Integer_Text_IO; procedure Numerics is procedure Quadro_Equation ( A, B, C : Float; R1, R2 : out Float; Valid : out Boolean) with Pre => A /= 0.0, Post => A /= 0.0 is EPS: constant Float := 0.01; package n renames Ada.Numerics.Elementary_Functions; Z: Float; d: Float; begin Z := B*B - 4.0 * A * C; if Z < 0.0 or abs(A) < EPS then R1 := 0.0; R2 := 0.0; Valid := False; return; end if; d := n.Sqrt(Z); R1 := (-B - d) / (2.0 * A); R2 := (-B + d) / (2.0 * A); Valid := True; end Quadro_Equation; R1, R2: Float; Valid : Boolean; function Min ( v1, v2: Integer) return Integer is begin if v1 < v2 then return v1; else return v2; end if; end Min; function Max (A, B: Integer) return Integer is (if A >= B then A else B); function Factorial (N: Positive) return Positive is begin if N <= 1 then return 1; else return N * Factorial(N - 1); end if; end; procedure Solve ( A, B, C : Float; R1, R2 : out Float; Valid : out Boolean) renames Quadro_Equation; package to renames Ada.Text_IO; package fo renames Ada.Float_Text_IO; package io renames Ada.Integer_Text_IO; X: Integer; begin Solve(1.0, 2.0, -1.0, R1, R2, Valid); if Valid then to.Put_Line("Valid"); else to.Put_Line("Not valid"); end if; to.Put_Line("Solutions:"); to.Put("Solution 1: "); fo.Put(R1, EXP => 0, AFT => 2); to.New_Line; to.Put("Solution 2: "); fo.Put(R2, EXP => 0, AFT => 2); to.New_Line; X := Min (1,2); to.Put("min(1,2) is = "); io.Put(X, WIDTH => 0); to.New_Line; X := Max (2,3); to.Put("max(2,3) is = "); io.Put(X, WIDTH => 0); to.New_Line; X := Factorial(10); to.Put("10! is = "); io.Put(X, WIDTH => 0); to.New_Line; end Numerics;