Need program to print all prime numbers?

,

how to write a programme in C language print all the prime numbers 2-1000???

I’m sorry this is not “write my homework” page…

Show us some effort - what you did.

You can start with a definition of a prime number.

1 Like

#include<stdio.h>
int main()
{
int i,j;
for(i=2;i<=1000;i++)
{
for(j=2;j<=1000;j++)
if(i%j==0)
break;
if(i==j)
printf("%d\t",j);}
return 0;
}

1 Like

use Sieve of Eratosthenes. wiki

1 Like

LINK TO PRIME NUMBER PROGRAM

Look at above link. Some basic optimization was handled

(y)
thnx a lot

For a number N,
For every number i, between 2 to N/2(2<= i <= N/2) check whether i divides N completely(check If i is a factor of N). Here is the full c program to print all prime numbers between 0 to K.