C++ code for checking for prime numbers not working

后端 未结 6 874
暖寄归人
暖寄归人 2021-01-29 05:24

I\'m having trouble with this C++ code. The integer num is a number that I want to check if it is prime. However this program is always returning false. It\'s proba

6条回答
  •  盖世英雄少女心
    2021-01-29 06:09

    bool isprime(int n)
    {
        if(n<2) return false;
        if(n==2)return true;
        for(int i=2;i<=sqrt(n);i++)
            if(n%i==0) return false;
        return true;
    }
    

提交回复
热议问题