Sunday, 11 March 2012

QBASIC Program To produce prime numbers

CLS
OPEN "Prime.txt" FOR OUTPUT AS #1
INPUT "UP TO WHICH NUMBER DO YOU
NEED"; N
DIM a(N)
a(1)=0 For i =2 To N/2 step 1 a(i)=1 For j=2 To N/i step 1
a(i*j)=0
Next j
Next i
For i =1 To N step 1
if a(i)=1 Then Print #1, i;"is prime"
Print '(empty if sent to notepad, Your
result is in the notepad,
check for PRIME.txt)
Next i
END

No comments:

Post a Comment

Please comment if there's anything you feel can be added or if you have any questions. Thanks.