sieve c program

Solutions on MaxInterview for sieve c program by the best coders in the world

showing results for - "sieve c program"
Nahel
30 Jan 2018
1#include <stdio.h> 
2#include <stdlib.h> 
3#include <conio.h> 
4#include <math.h> 
5 
6int main() 
7{ 
8	
9	int n; 
10	printf("Enter the limit: "); 
11	scanf("%d",&n); 
12	int A[n]; 
13	 
14
15	for(i=2;i<n;i++)A[i] = 1; 
16	 
17
18	 
19	for(i=2;i<n;i++) 
20	{ 
21		for(j=i;i*j<n;j++) 
22		{ 
23			A[i*j] = 0; 
24		} 
25	} 
26	
27	 
28	
29	 
30	for(i=2;i<n;i++) 
31	{ 
32		if(A[i]) 
33		{ 
34			printf("\n%d",i); 
35		} 
36	} 
37	getch(); 
38	return 0; 
39	 
40}