Created
November 24, 2014 11:22
-
-
Save shohan4556/6fa04a943806bf096eb2 to your computer and use it in GitHub Desktop.
প্রোজেক্ট ইউলার প্রবলেম # 07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<math.h> | |
#define N 1000000 | |
char p[N]; | |
int main() | |
{ | |
int i,j,root,k,nth_prime=0; | |
for(i=0;i<N;i++) | |
p[i]=1; // initialize array assume that all are prime | |
p[0]=p[1]=0; // zero and one are not prime | |
root=sqrt(N); // root max value of array | |
for(i=2;i<=root;i++) | |
if(p[i]==1){ // check is the number is prime | |
for(j=2;i*j<=N;j++) | |
p[i*j]=0; // cross the multiple of i composite number | |
} | |
// just print the prime numbers | |
for(k=2;k<=N;k++){ | |
if(p[k]==1) | |
nth_prime++; | |
//printf("%d ",k); | |
if(nth_prime==10001){ | |
printf("%d ",k); | |
break; | |
} | |
// printf("\n\n"); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment