0
How to count even odd prime number from 100 to 500?
any hint or solution?
5 Respuestas
+ 3
Sorry but your request is not clear..
you would count odd, even or prime numbers from 100 to 500? or all of these?
to determine if a number is odd or even you should use modus operation, but determining primes would be more complex.. please, take a look to my codes to find an hint..
+ 2
#include <stdio.h>
int main(){
int num=0, i;
for(i=100;i<=500;i++)
(i%2==0)? num++ : num;
printf("Total: %d", num);
return 0;
}
+ 1
A number x is prime if there's no number n with 1 < n <= sqrt(x) where x%n is 0.
Use the rule above and combine it with a for-loop that tests for every number from 100 to 500 and you have your answer.
0
With javascript:
var even = [ ];
for(i=500; i>100;--i){
for(x=i-1;x>=0;--x){
if(x==1){
even.push(i);
break;
}
else if(i%x == 0 ){
break;
}
}
}
- 1
There are no even prime numbers except 2. To count in range use sieve of erathostenes starting from 1, then just count primes in desired range