Your logic is flawed. You should first loop from 2 to 1000 to find all the primes and store them in array a. Then get input n, store in array b, loop array b, with j loop, output a[j] can be. Hope to adopt
#include<stdio.h>
int main(){
int n,i=1,j,count=0;
int a[1001];
while(~sacnf("%d",&n)){
for(i=2;;i++){
if(n%i==0){
break;
}else{
a[j++]=i;
if(j==1000)break;
}
}
for(j=1;j<=n;j++){
if(j==1){
printf("%d",a[j]);
}else{
printf(",%d",a[j]);
}
}
}
}
Task Description
Programming finds the first 1000 primes and stores them in an array, then inputs an integer N and outputs the value of the NTH prime.
Input format:
Input multiple groups of data, which are integers separated by several Spaces.
Output format:
For each n in the input data, output the value of the NTH prime number, with multiple outputs separated by commas.
input sample: < br / > 1, 2, 3, 4, 5 4 3 output sample: < br / > < br / > 2,3,5,7,11,7,5 < br / > input sample: < br / > 5 8 9 10, 100 200
Output Example :
11,19,23,29,541,1223
Input example :
996 997 998 999 1000 output sample: < br / > < br / > 7879788 3790 1790 7791 9
0 Answer
Your logic is flawed. You should first loop from 2 to 1000 to find all the primes and store them in array a. Then get input n, store in array b, loop array b, with j loop, output a[j] can be. Hope to adopt
这家伙很懒,什么都没留下...