C++ code for checking for prime numbers not working

后端 未结 6 876
暖寄归人
暖寄归人 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 CheckPrime(int num) {
        bool yayornay = true;
        for(int i = 2; i < num; i++) {
             if(num % i == 0) {
                 yayornay = false;
                 break;
             }
        }
        return yayornay;
    }
    

提交回复
热议问题