Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Prime = 1
- local i
- local count
- local primeCount
- local num = 1
- side = "right"
- term.redirect(peripheral.wrap(side))
- print("Welcome to my prime counting program. This program will display all numbers between 1 and the user defined number, making a note next to all prime numbers. Enter a value less than or equal to 0 to quit.")
- while num > 0 do
- print("")
- print("Please input your number: ")
- num = read()
- primeCount = 0
- for count=1,num,1 do
- Prime = 1
- if count == 1 then
- Prime = 0
- end
- if(count ~= 2 and Prime == 1)then
- if(math.fmod(count,2) == 0)then
- Prime = 0
- end
- for i=3,count,2 do
- if(math.fmod(count,i) == 0)then
- Prime = 0
- end
- end
- end
- if Prime == 1 then
- primeCount = primeCount + 1
- print(count .. " ---- " .. primeCount .. "th Prime")
- else
- print(count)
- end
- if count == num then
- print("")
- print("There are" .. primeCount .. " prime numbers between 1 and " .. num)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement