0

How to count even odd prime number from 100 to 500?

any hint or solution?

7th Feb 2017, 7:26 PM
Kirshan Singh Rajput
Kirshan Singh Rajput - avatar
5 Answers
+ 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..
7th Feb 2017, 8:30 PM
Michael Isac Girardi
Michael Isac Girardi - avatar
+ 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; }
7th Feb 2017, 8:19 PM
JĂ´natas Araripe
JĂ´natas Araripe - avatar
+ 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.
7th Feb 2017, 7:54 PM
Robobrine
Robobrine - avatar
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;         }     } }
7th Feb 2017, 8:07 PM
Manuel GarcĂ­a Montes
Manuel GarcĂ­a Montes - avatar
- 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
7th Feb 2017, 7:50 PM
Mieszko Mieruński
Mieszko Mieruński - avatar