嵌套的for循环 想半天不明白 帮忙解释下 谢谢
# include <stdio.h># define no 0
# define yes 1
int main(void)
{
long num; //要检查的数
long div; //潜在的除数
long lim; //限制的值
int prime; //质数 素数
printf("Please enter limit to values to be checked:");
printf("Enter q t quit.\n");
while (scanf("%ld",&lim) == 1 && lim > 0)
{
for (num = 2;num <= lim;num++)
{
for (div = 2,prime = yes;(div * div) <= num;div++)
if (num % div == 0)
prime = no;
if (prime == yes)
printf("%ld is prime.\n",num);
}
printf("Please enter another limit;");
printf("Enter q to quit.\n");
}
return 0;
}
求素数的