How to generate a range of floating-point numbers in Pascal

1 Answer

0 votes
program FloatRangeProgram;

{$mode objfpc}{$H+}

uses
  SysUtils; // FormatFloat

const
  StartValue = 0.0;
  StepSize   = 0.1;
  Count      = 11;  // Generates 0.0 through 1.0 inclusive

var
  I: Integer;
  Value: Double;

begin
  { Use an integer counter for predictable iteration. }
  for I := 0 to Count - 1 do
  begin
    { Compute each value independently. }
    Value := StartValue + (I * StepSize);

    Writeln(FormatFloat('0.0', Value));
  end;
end.



{
run:

0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0

}

 



answered Oct 4 by avibootz
...