#include<stdio.h>
int judgeprime(int n) //判断是不是素数
{
int i = 0;
int j = 1; //默认素数,判断之后若不是素数,返回j=0,否则返回j=1
for (i = 2; i < n; ++i)
{if (n%i == 0) //有其他共因数,不为素数{j = 0;break;}
}return j;
}
void judgeprintf(int num) //在num个数中判断判哪些是素数,并打印素数
{
int n = 0;
int j = 0;
int t = 1;
for (n = 2; n <= num; ++n) //数字区间 1--10
{if (judgeprime(n) == 1) //有其他的共因数,不是素数{printf("%d\n",n);}
}
}
int main(void)
{
int num = 0;
printf(“Input a num:\n”);
scanf(“%d”,&num);
judgeprintf(num); return 0;
}
``