用筛法求100之内素数

用筛法求100之内素数

任务描述

用筛法求100之内素数。

预期输出:

   2     3     5     7    11    13    17    19    23    29

   31    37    41    43    47    53    59    61    67    71

   73    ..    ..    ..    ..


源代码:

#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;
#include <math.h>


int main()
{
    
    // 请在此添加代码
    /********** Begin *********/
	int issu=1,i,j,count=0;
	for(i=2;i<100;i++){
		for(j=2;j<=i/2;j++){
			if(i%j==0){
				issu=0;
				break;
			}
		}
		if(issu){
			printf("%5d ",i);
			count++;
			if(count%10==0)printf("\n");
		}
		issu=1;
	}
    
    
    /********** End **********/
    return 0;
}
posted @ 2020-04-13 15:34  碎了的冰  阅读(324)  评论(0编辑  收藏  举报