Sequence of primes by trial division: Difference between revisions

Content added Content deleted
Line 209: Line 209:


(* ****** ****** *)</lang>
(* ****** ****** *)</lang>
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f SEQUENCE_OF_PRIMES_BY_TRIAL_DIVISION.AWK
BEGIN {
low = 1
high = 100
for (i=low; i<=high; i++) {
if (is_prime(i) == 1) {
printf("%d ",i)
count++
}
}
printf("\n%d prime numbers found in range %d-%d\n",count,low,high)
exit(0)
}
function is_prime(x, i) {
if (x <= 1) {
return(0)
}
for (i=2; i<=int(sqrt(x)); i++) {
if (x % i == 0) {
return(0)
}
}
return(1)
}
</lang>
{{out}}
<pre>
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
25 prime numbers found in range 1-100
</pre>

=={{header|Batch File}}==
=={{header|Batch File}}==
<lang Batch File>
<lang Batch File>