Output the Nth prime number

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

1 2 3 4 5
2
3
5
7
11

#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;

}

Supongo que te gusta

Origin blog.csdn.net/m0_74310050/article/details/129481949
Recomendado
Clasificación