prime_numbers.lua 510 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/lua
  2. -- will all the prime numbers below an inputted number
  3. print ("enter a number: ")
  4. a = io.read("*number")
  5. -- will return true or false, depending in the number is prime
  6. function prime (number)
  7. count_down = number
  8. while count_down > 2 do
  9. count_down = count_down - 1
  10. if (number % count_down) == 0 then
  11. return false
  12. end
  13. end
  14. return true
  15. end
  16. number = 2
  17. print("2")
  18. while number < a do
  19. number = number + 1
  20. if prime (number) then
  21. print (number)
  22. end
  23. end