TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
check_prime.cpp File Reference

A simple program to check if the given number is Prime or not. More...

#include <cassert>
#include <iostream>
Include dependency graph for check_prime.cpp:

Go to the source code of this file.

Namespaces

namespace  math
 for assert
 

Functions

bool math::is_prime (int64_t num)
 Function to check if the given number is prime or not.
 
static void tests ()
 Self-test implementations.
 
int main ()
 Main function.
 

Detailed Description

A simple program to check if the given number is Prime or not.

A prime number is any number that can be divided only by itself and 1. It must be positive and a whole number, therefore any prime number is part of the set of natural numbers. The majority of prime numbers are even numbers, with the exception of 2. This algorithm finds prime numbers using this information. additional ways to solve the prime check problem: https://cp-algorithms.com/algebra/primality_tests.html#practice-problems

Author
Omkar Langhe
ewd00010

Definition in file check_prime.cpp.

Function Documentation

◆ main()

int main ( void )

Main function.

Returns
0 on exit

Definition at line 81 of file check_prime.cpp.

81 {
82 tests(); // perform self-tests implementations
83 return 0;
84}
static void tests()
Self-test implementations.

◆ tests()

static void tests ( )
static

Self-test implementations.

Returns
void

Definition at line 62 of file check_prime.cpp.

62 {
63 assert(math::is_prime(1) == false);
64 assert(math::is_prime(2) == true);
65 assert(math::is_prime(3) == true);
66 assert(math::is_prime(4) == false);
67 assert(math::is_prime(-4) == false);
68 assert(math::is_prime(7) == true);
69 assert(math::is_prime(-7) == false);
70 assert(math::is_prime(19) == true);
71 assert(math::is_prime(50) == false);
72 assert(math::is_prime(115249) == true);
73
74 std::cout << "All tests have successfully passed!" << std::endl;
75}
bool is_prime(int64_t num)
Function to check if the given number is prime or not.