Algorithms_in_C++ 1.0.0
Set of 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:

Namespaces

namespace  math
 for IO operations
 

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

Function Documentation

◆ main()

int main ( void )

Main function.

Returns
0 on exit
81 {
82 tests(); // perform self-tests implementations
83 return 0;
84}
static void tests()
Self-test implementations.
Definition check_prime.cpp:62
Here is the call graph for this function:

◆ tests()

static void tests ( )
static

Self-test implementations.

Returns
void
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}
T endl(T... args)
bool is_prime(int64_t num)
Function to check if the given number is prime or not.
Definition check_prime.cpp:31
Here is the call graph for this function: