#include <stdio.h>
#define N 1000
main()
{
int i,j, arr[N+1];
//Set All Array index to 1
for(i=2,arr[0]=0;i<N;i++)
arr[i]=1;
//Now seeting all Non-prime Number to 0
for( i = 2; i < N/2; i++)
{
for ( j = 2; j < N/i ; j++)
{
arr[i*j] = 0;
}
}
//Printing all Prime numbers
for ( i=1; i < N; i++)
{
if ( arr[i])
printf("%d\t",i);
}
printf("\n");
}
RTOS, Linux Kernel internal, OS-Programming C & Data Structures, Debugging, Optimizations, Makefiles and Wireless Technologies (Wi-Fi ,LTE and LTE-Advanced )
Search This Blog
Monday, May 16, 2016
Print All prime number less than 1000 (or Any Range)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment