+ 6

I want Ideas

what can we do with numbers like test it is prime or not,even or not

17th Jan 2017, 2:27 PM
Shirious
Shirious - avatar
15 Respostas
+ 13
@ValentinHacker Prime numbers are numbers that can be divided only by 1 or itself. like 2, 5, 23
17th Jan 2017, 5:41 PM
Gami
Gami - avatar
+ 12
@ValentinHacker *Divided without getting a remainder ;)*
18th Jan 2017, 6:50 AM
Gami
Gami - avatar
+ 10
num%2==0 <- even num%2!=0 <- odd (not sure what "prime" means… /: )
17th Jan 2017, 2:33 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 9
@Gami 2 can be divided with 1.1,1.2,1.3……… ~_~
17th Jan 2017, 7:23 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 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 :)
17th Jan 2017, 2:39 PM
Will_De
Will_De - avatar
+ 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.
18th Jan 2017, 4:59 AM
Bekir Uzun
Bekir Uzun - avatar
+ 3
@ValentineHacker not including fractions...
17th Jan 2017, 7:40 PM
Almog Ben-Chen
Almog Ben-Chen - avatar
+ 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...
17th Jan 2017, 7:45 PM
visph
visph - avatar
+ 3
@visph clever... didnt think of that
17th Jan 2017, 7:48 PM
Almog Ben-Chen
Almog Ben-Chen - avatar
+ 3
@Bekir Uzun Your code has an error. Where it says "prime" should say "isPrime"
18th Jan 2017, 6:29 PM
Iván
Iván - avatar
+ 3
@Ivan Thanks. Fixed it
22nd Jan 2017, 7:54 AM
Bekir Uzun
Bekir Uzun - avatar
+ 2
You want ideas?... I want money :P
17th Jan 2017, 4:07 PM
visph
visph - avatar
+ 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.
17th Jan 2017, 7:38 PM
Almog Ben-Chen
Almog Ben-Chen - avatar
+ 2
Check the code I expect more biodata's
18th Jan 2017, 12:51 PM
Shirious
Shirious - avatar