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

A C++ Program to check whether a pair of numbers is an amicable pair or not. More...

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

Go to the source code of this file.

Namespaces

namespace  math
 for assert
 

Functions

int math::sum_of_divisor (int num)
 Function to calculate the sum of all the proper divisor of an integer.
 
bool math::are_amicable (int x, int y)
 Function to check whether the pair is amicable or not.
 
static void tests ()
 Self-test implementations.
 
int main ()
 Main function.
 

Detailed Description

A C++ Program to check whether a pair of numbers is an amicable pair or not.

An Amicable Pair is two positive integers such that the sum of the proper divisor for each number is equal to the other number.

Note
Remember that a proper divisor is any positive whole number that divides into a selected number, apart from the selected number itself, and returns a positive integer. for example 1, 2 and 5 are all proper divisors of 10.
Author
iamnambiar

Definition in file check_amicable_pair.cpp.

Function Documentation

◆ main()

int main ( void )

Main function.

Returns
0 on exit

Definition at line 81 of file check_amicable_pair.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 67 of file check_amicable_pair.cpp.

67 {
68 assert(math::are_amicable(220, 284) == true);
69 assert(math::are_amicable(6368, 6232) == true);
70 assert(math::are_amicable(458, 232) == false);
71 assert(math::are_amicable(17296, 18416) == true);
72 assert(math::are_amicable(18416, 17296) == true);
73
74 std::cout << "All tests have successfully passed!" << std::endl;
75}
bool are_amicable(int x, int y)
Function to check whether the pair is amicable or not.