求1-10000所有的素数

#include <stdio.h>
#include <math.h>
int main()
{
    int i,j,m;
    printf("2 ");
    for(i=3;i<=10000;i++){
        m = sqrt(i);
        for(j=2;j<=m;j++){
            if(i%j==0){
                break;
            }
        }
        if(j>=m+1){
            printf("%d ",i);
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/zoulingjin/p/9629822.html