Output the Nth prime number
describe
Program to find the first 1000 prime numbers and store them in an array, then input an integer N and output the value of the Nth prime number.
Input and output example
enter |
output |
|
Example 1 |
|
|
#include<stdio.h>
int main(){
int n,i,count=0,j;
while(~scanf("%d",&n)){
count=0;
for(i=2;;i++){
for(j=2;j<=i;j++){
if(i%j==0){
break;
}
}
if(i==j){
count++;
}
if(count==n){
break;
}
}
printf("%d\n",i);
}
return 0;
}