10001th prime: Difference between revisions

m
typo
imported>Nmz
(→‎Idiomatic awk: legible variables)
m (typo)
 
(5 intermediate revisions by 3 users not shown)
Line 117:
}
 
BEGIN { print PrimePosPrimePosition(10001) }
 
</syntaxhighlight>
Line 658:
 
=={{header|Fermat}}==
<syntaxhighlight lang="fermatpascal">
Prime(10001);
</syntaxhighlight>
Line 914:
<syntaxhighlight lang="parigp">prime(10001)</syntaxhighlight>
{{out}}<pre>%1 = 104743</pre>
 
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
Program nth_prime;
 
Function nthprime(x : uint32): uint32;
Var primes : array Of uint32;
i,pr,count : uint32;
found : boolean;
Begin
setlength(primes, x);
primes[1] := 2;
count := 1;
i := 3;
Repeat
found := FALSE;
pr := 0;
Repeat
inc(pr);
found := i Mod primes[pr] = 0;
Until (primes[pr]*primes[pr] > i) Or found;
If Not found Then
Begin
inc(count);
primes[count] := i;
End;
inc(i,2);
Until count = x;
nthprime := primes[x];
End;
 
Begin
writeln(nthprime(10001));
End.
</syntaxhighlight>
{{out}}
<pre>
104743
</pre>
 
=={{header|Perl}}==
Line 1,212 ⟶ 1,252:
<pre>
104743
</pre>
 
 
=={{header|Zig}}==
<syntaxhighlight lang="zig">
const std = @import("std");
const stdout = @import("std").io.getStdOut().writer();
 
const limit = 10001;
 
fn isPrime(x: usize) bool {
if (x % 2 == 0) return false;
 
var i: usize = 3;
while (i * i <= x) : (i += 2) {
if (x % i == 0) return false;
}
return true;
}
 
pub fn main() !void {
var cnt: usize = 0;
var last: usize = 0;
var n: usize = 1;
 
while (cnt < limit) : (n += 1) {
if (isPrime(n)) {
cnt += 1;
last = n;
}
}
try stdout.print("{d}st prime number is: {d}\n", .{ limit, last });
}
</syntaxhighlight>
 
{{out}}
<pre>
10001st prime number is: 104743
</pre>
22

edits