只能被本身和1整除的数--素数
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
//1.试除法--低阶
int main()
{
int i = 0;
int count=0;
for (i = 100; i <= 200; i++)
{
int j = 0;
for (j = 2; j <= i; j++)//j从2开始是为了直接避免1这个数被除
{
if (i % j == 0)
{
break;//break跳出的是循环
}
}
if (j == i)
{
count++;
printf("%d ", i);
printf("count= %d\n", count);
}
}
return 0;
}
开平方法
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
int main()
{
int i = 0;
int count = 0;
for (i = 100; i <= 200; i++)
{
int j = 0;
for (j = 2; j <= sqrt(i); j++)//sqrt()开平方,库函数 <math.h>
{
if (i % j == 0)
{
break;
}
}
if (j > sqrt(i))
{
count++;
printf("%d ",i);
}
}
printf("\ncount= %d\n",count);
return 0;
}
标签:count,200,SECURE,CRT,int,质数,100,include
From: https://blog.51cto.com/u_16425777/8791682