/*=========================================
* Copyright (c) 2020, 逐风墨客
* All rights reserved.
*
* 文件名称:study_nprime.c
* 运行环境:Linux操作系统
* 功能描述:用开根号的办法查找1000以内的素数
=========================================*/
#define MAX_NUM 1000
#include <stdio.h>
#include <math.h>
int main(void)
{
int i, j, k;
for (i=1; i<MAX_NUM; i++)
{
k = (int)sqrt(i);
for (j=2; j<=k; j++)
{
if (i%j == 0)
{
break;
} // end of if
} // end of for
if (j > k)
{
printf("%5d", i);
}
} // end of for
printf("\n");
return 0;
}
程序运行结果: