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

Namespaces

namespace  math
 for IO operations
 

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

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_amicable_pair.cpp:67
Here is the call graph for this function:

◆ tests()

static void tests ( )
static

Self-test implementations.

Returns
void
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}
T endl(T... args)
bool are_amicable(int x, int y)
Function to check whether the pair is amicable or not.
Definition check_amicable_pair.cpp:58
Here is the call graph for this function: