priest170234
New Member
- Reaction score
- 0
Okay, I tried to code this myself. (Perhaps the first time I am coding myself, without help). Review this for me!
This is a function to check whether a number is prime or not.
Definition of Prime number: A number whose factors are 1 and itself
Numbers less than or equal to 1 are not prime.
This is a function to check whether a number is prime or not.
Definition of Prime number: A number whose factors are 1 and itself
Numbers less than or equal to 1 are not prime.
JASS:
scope CheckPrime
globals
integer int // Constant, does not change at ALL until checked = false
integer int_2 // Changes
boolean checked = false
boolean isPrime
endglobals
function CheckPrime takes integer number returns boolean
if(number<=1) then
call BJDebugMsg("Please enter a value larger than 1!")
set isPrime = false
else
////////////////////////////////////////////
if(checked == false) then
set checked = true
set int = number
endif
////////////////////////////////////////////
set int_2 = number
if (ModuloInteger(int, int_2) == 0) and (int != int_2) then // Divisible, and int not equal to int_2, NOT PRIME
set int_2 = 0
endif
if (int_2 == 0) then // If Its not a Prime Number
call BJDebugMsg(I2S(int)+" is NOT Prime!")
set checked = false
set isPrime = false
else // Checking...
if(int_2-1 == 1) then // If the next number becomes 1, and so far it still prime, then the number IS PRIME!
call BJDebugMsg(I2S(int)+" IS Prime!")
set checked = false
set isPrime = true
else
set int_2 = int_2 - 1
call CheckPrime(int_2)
endif
endif
endif
return isPrime
endfunction
endscope