jeudi 22 avril 2021

Need to get this program checking if Number is prime but without if statement, how to make it work for 1? main can not be changed

Need to get this program checking if Number is prime but without if statement, how to make it work for 1? main can not be changed

#include <iostream>

bool prime(int x){

    for (int i = 2; i < x; ++i){
        return (x % i != 0);
    }
}

int main() {
    std::cout << std::boolalpha << prime(1344) << std::endl;
}

Aucun commentaire:

Enregistrer un commentaire