A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Prime Number in Julia page! Here, you'll find the source code for this program as well as a description of how the program works.
function err()
return "Usage: please input a non-negative integer"
end
function isPrime(num)
# handle 0 and 1
if num <= 1
return "composite"
end
# default handler
for i in 2:sqrt(num) #loop starting at 2, ending at the squareroot of the input
if (num % i == 0)
return "composite"
end
end
return "prime"
end
#check for a valid input
try
n = parse(Int, ARGS[1])
if n < 0
println(err())
else
println(isPrime(n))
end
catch e
println(err())
end
Prime Number in Julia was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.