sieve of eratosthenes c

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

showing results for - "sieve of eratosthenes c"
Gabriella
21 Apr 2016
1//sieve of eratosthenes or prime of sieve
2#include<iostream>
3#include<math.h>
4using namespace std;
5void primeofsieve(long long int n)
6{
7	long long int arr[n]={};
8	for(int i=2;i<=sqrt(n);i++)
9	{
10		for(long long int j=i*i;j<=n;j+=i)
11			arr[j]=1;
12	}
13	for(long long int i=2;i<=n;i++)
14	{
15	    if(arr[i]==0)
16	    	cout<<i<<" ";
17	}
18
19
20}
21int main()
22{
23
24	#ifdef _DEBUG
25	freopen("input.txt", "r", stdin);
26	freopen("output.txt", "w", stdout);
27    #endif
28	long long int n;
29	cin>>n;
30	cout<<"PRIME NUMBERs ARE : ";
31	primeofsieve(n);
32	return 0;
33}
Sofie
08 May 2017
1/******************************************************************************
2
3                            Online C Compiler.
4                Code, Compile, Run and Debug C program online.
5Write your code in this editor and press "Run" button to compile and execute it.
6
7*******************************************************************************/
8
9#include <stdio.h>
10#include <math.h>
11#include <stdbool.h>
12
13int main()
14{
15    int n,i,j; //declaring required variables
16    scanf("%d",&n); //scanning n(limit numbers)
17    bool arr[n+1]; //declaring an array which contains true and false values
18    arr[1]=false; //setting the first index to false (1 is not a prime number)
19    
20    for(i=2;i<=n;i++){
21        arr[i]=true; //we are assuming that all the numbers are true which means prime
22    }
23    
24    for(i=2;i<sqrt(n)+1;i++){ //running loop to the sqrt on n + 1
25        if(arr[i]==true){ //if the number is true of prime 
26            for(j=i+i;j<=n;j+=i){ //run the loop to n
27                arr[j]=false; //assume that the divisble numbers are not prime
28            }
29        }
30    }
31    
32    for(i=2;i<=n;i++){
33        if(arr[i]==true){
34            printf("%d ",i); //printing the numbers if that is true 
35        }
36    }
37    
38    
39
40    return 0;
41}
42
43
queries leading to this page
sieve of eratosthenes log c 2b 2bsieve of erathowhat is prime sievesieve of erathosesc program for sieve of eratosthenes find all prime numbers less than 100 gfg code using sieve of erasthprime seiveisieve of primes c 2b 2bprime sieve of size 1000000primes number sievesieve implimentationowing the original and n c3 a4ive definition of the method 3a starting from 2 2c mark all the multiples of that number as not primes and then move to the next unmarked number when there are no more numbers left 2c the unmarked numbers are the primes example 3aprime numbers using sieve of eratosthenessieve of eratosthenes code for finding prime numbers upto a n inc 2b 2ba question based on gcd with the sieve of eratosthenes sieve of eratosthenes c 2b 2bsieve algorithm prime numbers sieve of eratosthenessieve of eratosthenes c program fsieveoferatosthenessieve of eratosthenes in cdevelop an algorithm which finds the prime number up to nprime numbers less than k c 2b 2b nlogn sievesieve primehw sieve of eratosthene optimization medium time function in coptimization time in sieve of eratosthenes in c sieve eratosthenes prime numbersseive geeksefficient algorithm to find prime given an arraycode for sieve of eratosthenessieve algorithm for finding prime numberssieve of eratosthenes prime numbersmost efficient way to generate prime numbers till a given n valuemost efficient prime number algorithmeratosthenes sieveeratosthenes 27 sieve cgenerating n prime numbers using seive of err in c 2b 2bsimple prime algorithm implementionsieve of eratosthenes method with an examplehow old is sieve of eratostheneswhen seive code is used in prime numbersprime number java sieve of eratosthenesalgorithm for finding all prime numbers up to any given big limitsieve algorithm javaprint first n prime numbers in c 2b 2b seive of eratostheneshwo to generate sieve of prime numbers for largesieve of eratosthenes algorithm in chw sieve of eratosthenes time funciton in cprint prime numbers up to less than n in c in o 28n 29 time complexitysieve of eratosthenes sieve of eratosthenes program in c using functionswhich of the following algorithm 28s 29 uses prime numberssieve of eratosthenes n number of prime numbersfind the prime no in range cpp seiveeratosthenes prime numbers sievesieve of eratosthenes algorithm sieve algorithm in c gfg sieve of eratosthenessieve geeks for geekseratosthenes sieve c 2b 2bsieve of prime numbersprime numbers sieve of eratosthenesseive algorithmeratosthenes sieve codeeratosthenes e2 80 99s sieve algorithmcheck if a number is prime using sieveusing sieve of eratosthenesprimes sievesieve prime algorithmhow to find prime numbers seize of estrogensieve of eratosthenescalculate prime numbers with sieve of eratosthenesis prime sievesieve of eratosthenes implementation at gfgsieve of eratosthenes csieve and prime sievesieve of eranthosessieve of erasieve code in c 2b 2bseives algo for primessieve of eratosthenes code in c 2b 2bsieve of primesseive codesieve algorithm 3fsieve prime complexityfind all the prime numbers from 1 to n using sieve of erastothenesc program for sieve of eratosthenes functionsprime sievecheck prime sieve of eratosthenessieve of eratosthenes program in csieve of eratosthenes codeprime numbers between c 2b 2b using sievesieve algoan algorithm which finds the prime number up to n 28sieve prime numbersieve eratosthenesthe sieve of eratosthenes is an algorithm for finding all prime numbers less than or equal to a number n read about this algorithm on wikipedia and implement it in a python program filename 3a find primes pysieve of eratoserasthones sieveoptimization time seven of erastothenes cerasthonus sievewhat is the sieve primessieve of eratosthenes javasieve of eratosthenes implementationsieve of eresthossis gfgprime1 spoj sieve of eratosthenesc 2b 2b sieve of eratosthenessieve prime numbersfind first n prime numbers c 2b 2b sieve of eratostheneseratostheens sievesieve for primesseive of erathones codesieve of eratosthenealll prime numbers using seive of eratostethensprimes sieve ofsieve algorithmsieve of eratosthenes other namewhy does the sieve of eratosthenes is correctprime sieve methodprinting prime numbers seivethe sieve of eratosthenessieve of primebuilt in function for sieve of eratosthenesprime of sive questionsieve of ertosthenessievegeeksprint first n prime numbers using sieveprime eratosthenes in cpperatosthenes algorithmsieve of eratosthenes for prime numberssieve primeslogic for sieve of eratosthenessieve gfga program that uses the sieve of eratosthenes to find all the prime numbers between 2 and 5000 c 2b 2ba program that uses the sieve of eratosthenes to find all the prime numbers between 2 and 5000 sieves algorithmoptimization seven of erastothenes csieve of erastosthenessieve of eratosthenes algorith 2csieve of eratosthenes cpp 23include 3cbits 2fstdc 2b 2b h 3e using namespace std 3b 23define max 10000000 bool prime 5bmax 2b1 5d 3b void sieveoferatosthenes 28 29prime number sieve of eratosthenessieve method of number of primesoptimization sevent of erastotenesprime number sievesieve of eratosthenes generator first n prme numbersprime sieve c 2b 2bsieve of eratosthenes c 2b 2bprime seive codefirst n prime numbers using sieve of eratosthenes 22sieve of eratosthenes c program time execution optimizationin sieve prime why use i 2aigenerate a list of all numbers between 0 and n 3b mark the numbers 0 and 1 to be not primesieve of eratosthenes c programranged sieve of eratosthenes javaeratosthenes 26rsquo 3bs sieve algorithmapplication of sieve of eratosthenessieve of eratosthenes c 2b 2b proofsieve of eratostehenescomplexity of finding all prime numberseratosthenes sieve csimple prime sieveoptimize prime sieve in c 2b 2bprime number sieve c 2b 2bsieve de eratostenessieve c 2b 2bprime of sieveprime sieve algorithmseratosthenes prime sievesieve of eratosthenes algorithmsieve of eratosthenes in cppoptimization time in sieve of eratosthenes code csieve of eratostheneswhat is sieve of eratosthenesprime sieve function c 2b 2bsieve of eratosthenes c