写代码的日常——判断素数

输出100到200之间的素数

#include<stdio.h>
int main()
{
 int i = 0, count = 0;
 for (i = 100; i <= 200; i++)//遍历100到200之间的所有数
 {
  int j=0;
  for (j = 2; j < i ; j++)//除了1和本身其他都不能被整除
  {

   if (i%j == 0)
    break;
  }//跳出循环有两种可能,判断
  if (i == j)
  {
   count++;
   printf("%d\n", i);
  }
 }
printf("count=%d\n", count);
  getchar();
  return 0;
}

猜你喜欢

转载自blog.csdn.net/a_struggling_monkey/article/details/78560829