第18周OJ测试项目4--找出素数

来源:互联网 发布:黄芪泡水 知乎 编辑:程序博客网 时间:2024/05/17 08:55

输入若干个正整数,将其中的素数输出来。

代码如下:

#include <iostream>#include <cmath>using namespace std;bool isPrime(int n);int main( ){    int n;    while(cin>>n)    {        if(isPrime(n))            cout<<n<<endl;    }    return 0;}bool isPrime(int n){    int i;    for (i=2; i<=sqrt(n); ++i)        if (n%i==0)            break;    if (i>sqrt(n))        return n;    else        return 0;}



运行结果:



程序运行的时候有警告:control reaches end of non-void function [-Wreturn-type]   求路过的大神解释下与给个解决方案,碰到过好几次这种情况了,度娘给的解释看是看懂了,还是不知道原因和消除警告的方案。

1 0
原创粉丝点击