C语言 求100-200之间 前n个素数

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <math.h>
 4 int main()
 5 {
 6 
 7   int i,j,n,l;
 8   int count=0;
 9    scanf("%d",&n);
10    for(i=100;i<200;i++)
11    {
12       l=1;
13       for(j=2;j<=sqrt((double)i);j++)
14       {
15        if(i%j==0)
16        {
17         l=0;break;
18        }
19       }
20       if(l==1)
21       {
22 
23           count++;
24 
25           if(count>n){
26             break;
27           }else {
28         printf("%d ",i);
29           }
30 
31 
32 
33           }
34    }
35 
36 
37 return 0;
38 }

 

posted @ 2021-11-27 16:10  程序员小贤  阅读(202)  评论(0)    收藏  举报