+ 6
I want Ideas
what can we do with numbers like test it is prime or not,even or not
15 Answers
+ 13
@ValentinHacker Prime numbers are numbers that can be divided only by 1 or itself. like 2, 5, 23
+ 12
@ValentinHacker *Divided without getting a remainder ;)*
+ 10
num%2==0 <- even
num%2!=0 <- odd
(not sure what "prime" means… /: )
+ 9
@Gami 2 can be divided with 1.1,1.2,1.3……… ~_~
+ 5
a for loop that tries to divide the given number with a num in range(2,number-1) and convert it to an int. If it only gave typeerror, it is a prime :)
+ 5
you can check primes like that:
bool isPrime = true;
for(int i = 2; i <= n/2; i++){
if(n % i == 0){
isPrime = false;
break;
}
}
where n is the number that you want to check and isPrime is boolean variable that holds if n is prime or not. Note that checking n/2 numbers is enough to find if n is prime or not. Loop must start from 2 otherwise it wont work correctly. Because n % 1 == 0 will always return true. No matter what n is.
+ 3
@ValentineHacker not including fractions...
+ 3
@Almog Bercovitch:
Between 0 and square root of N is good enough, as if ( N == a * b ) if ( a >= n ) then ( b <= n ), so values greater than case ( a == b ) is already tested...
+ 3
@visph clever... didnt think of that
+ 3
@Bekir Uzun Your code has an error. Where it says "prime" should say "isPrime"
+ 3
@Ivan Thanks. Fixed it
+ 2
You want ideas?... I want money :P
+ 2
for prime do a loop between 0 and N that checks if N%i==0.
if you really want tog get fancy you can make it recursive, while it does N%i only if i is prime.
+ 2
Check the code
I expect more biodata's