DEV Community

Pratik Jadhav
Pratik Jadhav

Posted on

Wilson's Primality Test to check whether a number is prime or not?

#include <bits/stdc++.h>
using namespace std;

int fact(int n){
    if(n<=1){
        return 1;
    }
    else{
        return n*fact(n-1);
    }
}

bool isPrime(int p){
    int w=p-1;
    if(p==4){
        return false;
    }
    else{
        if((fact(w)+1)%p==0){
            return true;
        }
        else{
            return false;
        }
    }
}


int main(){

    isPrime(7) ? cout << " true\n" : cout << " false\n";

    return 0;
}
Enter fullscreen mode Exit fullscreen mode


cpp

Top comments (0)