Loops/Increment loop index within loop body: Difference between revisions
Loops/Increment loop index within loop body (view source)
Revision as of 23:21, 1 September 2020
, 3 years agono edit summary
m (→{{header|Phix}}: is_prime() now a builtin) |
MaiconSoft (talk | contribs) No edit summary |
||
Line 1,465:
42 -> 99,504,028,301,131
</pre>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{Trans|C#}}
<lang Delphi>
program Increment_loop_index_within_loop_body;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
function IsPrime(const a: UInt64): Boolean;
var
d: UInt64;
begin
if (a < 2) then
exit(False);
if (a mod 2) = 0 then
exit(a = 2);
if (a mod 3) = 0 then
exit(a = 3);
d := 5;
while (d * d <= a) do
begin
if (a mod d = 0) then
Exit(false);
inc(d, 2);
if (a mod d = 0) then
Exit(false);
inc(d, 4);
end;
Result := True;
end;
var
i, n: UInt64;
begin
FormatSettings.ThousandSeparator:= ',';
i := 42;
n := 0;
while (n < 42) do
begin
if (isPrime(i)) then
begin
inc(n);
Writeln('n = ', n: -20, ' ', floattostrF(i, ffNumber, 20,0):20);
i := 2 * i - 1;
end;
inc(i);
end;
readln;
end.</lang>
{{out}}
Same of [[#C#]].
=={{header|Dyalect}}==
|