文章

34

粉丝

179

获赞

13

访问

184.3k

头像
浙江工商大学(2019上机题-素数)
备考心情
发布于2022年2月26日 13:52
阅读数 5.4k

没有输入,输出100-200内素数的个数以及具体值 

#include <iostream>
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int a[200]={0};
int main(){
    int count=0;  // count用于记录非素数的个数
    for(int i=100;i<=200;i++){
        for(int j=2;j<=sqrt(i);j++){
            if(i %j ==0){ //非素数
                a[i]=1;
                count++;
                break;
            }
        }
    }
    printf("%d\n",101-count);
    for(int i=100;i<=200;i++){
        if(a[i]==0 && i !=199)
            printf("%d ",i);
        if(a[i]==0 && i==199)
            printf("%d",i);
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发