Answers for "sieve c program"

C
0

sieve c program

#include <stdio.h> 
#include <stdlib.h> 
#include <conio.h> 
#include <math.h> 
 
int main() 
{ 
	
	int n; 
	printf("Enter the limit: "); 
	scanf("%d",&n); 
	int A[n]; 
	 

	for(i=2;i<n;i++)A[i] = 1; 
	 

	 
	for(i=2;i<n;i++) 
	{ 
		for(j=i;i*j<n;j++) 
		{ 
			A[i*j] = 0; 
		} 
	} 
	
	 
	
	 
	for(i=2;i<n;i++) 
	{ 
		if(A[i]) 
		{ 
			printf("\n%d",i); 
		} 
	} 
	getch(); 
	return 0; 
	 
}
Posted by: Guest on November-19-2020

Code answers related to "C"

Browse Popular Code Answers by Language