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.

I changed that code so it doesn't return those numbers under 2 that AREN'T prime. That way I had my code at first didn't let it show the numbers that weren't prime, but it was a bit slow.

Graphics 500,700,1,2

;For n = 0 To 21
;	Text 0,n*30,"n = " + n
;	If Prime(n) = 1
;		Text 20,(n*30)+10,"Is n("+n+") a prime number? Yes"
;			Else
;				Text 20,(n*30)+10,"Is n("+n+") a prime number? No"
;	EndIf
;Next

For n = 1 To 100000
	If Prime(n) = 1
		Print n
	EndIf
	If KeyHit(1) End
Next

WaitKey()

Function Prime(prime%)			
	For divide = 2 To Sqr(prime)
		If prime Mod divide = 0
			Return False
		EndIf
	Next
	
	If prime => 2
		Return True
			Else
				Return False
	EndIf
End Function