0
do anyone know how to print all the prime numbers within a given range
6 Respuestas
+ 2
Javascript tutorial, but can help to implement such prime number search:
https://code.sololearn.com/WPXD8LSoeiIL/?ref=app
+ 2
take two inputs start and end
and two for loops as (say i and j) variables.
and a flag variable
run first for (i.e. i) loop from the start value and increment it till end value.. and initialise the flag value to zero..
then run second for (i.e. j) loop from 2 and increment it..till the j value is less than i.
and in the same loop check a condition that whether i is fully divided by j, then increment the value of j..
and atlast check if the value of flag remains zero then print the value of i
0
You can start with 6n+/-1 or any other filter and do a sieve of Eratosthenes or segmented sieve of Eratosthenes or any other sieve of your choosing.
for an arbitrary range, 6n+/-1 will weed out those divisible by 2 and by 3. then there are primality tests. AKS comes to the mind off handed. There are more. Chances are, they are available as library somewhere. The numbers flagged probably prime by these tests can then be thoroughly tested to eliminate false positives.
if you are asking for the code, it is a different question entirely.
0
for(int i=min; i<max; i++){
bool prime=true;
for(int j=2; j<i; j++)
if(i%j==0) prime=false;
if(prime) cout << i;
}
0
thankss... a lot everyone.....