blob: cdd308dc2d86b568db81aeb8675a7859d5dabbd3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
!Program to calculate all primes below a certain value
program sieveOfEratosthenes
!define variables
int::n
n=10000
int dimension(10000)::checks
int::i
int::j
!initialise array
do i=2,n
checks(i)=1
end do
i=2
!search for primes
do while(i<root(n))
if checks(i)==1 then
j=i**2
do while(j<n)
checks(j)=0
j=j+i
end do
end if
i=i+1
end do
!output primes found
print*,"Primes below ",n
do i=2,n-1
if checks(i)==1 then
print*,i
end if
end do
end program sieveOfEratosthenes
!Function to find the square root of a value
function real root(int value)
real::result
result=1
int::count
do count=0,10
result =(result+value/result)/2
end do
return result
end
|