A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/da/d7b/primality__test_8cpp_source.html below:

TheAlgorithms/C++: others/primality_test.cpp Source File

1 12#include <iostream> 13 18bool IsPrime

(

int

number) {

19 if

(((!(number & 1)) && number != 2) || (number < 2) ||

20

(number % 3 == 0 && number != 3))

21 return false

;

22 23 for

(

int

k = 1; 36 * k * k - 12 * k < number; ++k) {

24 if

((number % (6 * k + 1) == 0) || (number % (6 * k - 1) == 0))

25 return false

;

26

}

27 return true

;

28

}

29 31int main

() {

32 // Main Function 33

std::cout <<

"Enter the value of n to check if Prime\n"

;

34 int

n;

35

std::cin >> n;

36 if

(

IsPrime

(n))

37

std::cout << n <<

" is Prime"

<< std::endl;

38 else 39

std::cout << n <<

" is not Prime"

<< std::endl;

40 41 return

0;

42

}

IsPrime

bool IsPrime(int number)

Definition primality_test.cpp:18 main

int main()

Definition primality_test.cpp:31

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4