离大谱零分求助
查看原帖
离大谱零分求助
609989
scrrr楼主2022/2/19 21:43

每个数都是和答案一样的

#include<stdio.h>
#include<math.h>
int isPrime(int n) {
    int i,s=1;
    for(i=2; i<=sqrt(n); i++) {
        if (n%i==0){
            s=0;
            break;
        }
    }
    return s;
}
int main()
{
//    freopen("out.txt","w",stdout);
    int l,i,sum,cnt=0;
    i=2;
    scanf("%d",&l);
    while(sum<=l){
       if(isPrime(i)==1){
            sum+=i;
            printf("%d\n",i);
            cnt++;
       }
       i++;
    }
    printf("%d\n",cnt);

}

破防了,大佬帮我看看是哪里错了

2022/2/19 21:43
加载中...