Prime Finder

Blitz3D Forums/Blitz3D Programming/Prime Finder

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

And, to prove the speed of this code, try this. It's quite fun!
Graphics 500,700,1,2

For n = 0 To 200000
		
	If Prime(n) = 1
	
		Print n
		
	EndIf

Next

WaitKey()

Function Prime(prime%)
	
	Local Not_Primes% ; If the givin number is prime Ex: 5
			  ; then it will not divide evenly by anything between 2 and the square root of five
					
	For divide = 2 To Sqr(prime)
		
		If prime Mod divide = 0
			
			Return False
				
		EndIf
			
	Next
		
	Return True
		
End Function