判断101-200之间有多少个素数,并输出所有素数。
# include <stdio.h>
# include <math.h>
int main(void)
{
int m,i,h = 0,leap = 1;
double k;
printf("\n");
for (m = 101;m <= 200;m ++)
{
k = sqrt(m + 1);
for (i = 2;i <= k;i ++)
{if (m%i == 0)
{leap = 0;
break;
}
if(leap)
{
printf("%-4d", m);
h++;
if (h%10 == 0)
printf("\n");
}break;
}
leap = 1;
}
return 0;
}
# include <stdio.h>
# include <math.h>
int main(void)
{
int m,i,h = 0,leap = 1;
double k;
printf("\n");
for (m = 101;m <= 200;m ++)
{
k = sqrt(m + 1);
for (i = 2;i <= k;i ++)
{if (m%i == 0)
{leap = 0;
break;
}
if(leap)
{
printf("%-4d", m);
h++;
if (h%10 == 0)
printf("\n");
}break;
}
leap = 1;
}
return 0;
}