Skip to content

Commit b157b6f

Browse files
authored
Update gcd_of_n_numbers.cpp
1 parent 402ed85 commit b157b6f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

math/gcd_of_n_numbers.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <cassert> /// for assert
1717
#include <iostream> /// for IO operations
1818
#include <optional> /// for std::optional
19+
1920
/**
2021
* @namespace math
2122
* @brief Maths algorithms
@@ -42,6 +43,7 @@ int gcd_two(int x, int y) {
4243
}
4344
return gcd_two(y, x % y); // Euclidean method
4445
}
46+
4547
/**
4648
* @brief Function to check if all elements in the array are 0
4749
* @param a Array of numbers
@@ -58,6 +60,7 @@ bool check_all_zeros(const std::array<int, n>& a) {
5860
* @param a Array of integers to compute GCD for
5961
* @return std::optional<int> GCD of the numbers in the array or std::nullopt if undefined
6062
*/
63+
6164
template <std::size_t n>
6265
std::optional<int> gcd(const std::array<int, n>& a) {
6366
// GCD is undefined if all elements in the array are 0
@@ -81,6 +84,7 @@ std::optional<int> gcd(const std::array<int, n>& a) {
8184
* @brief Self-test implementation
8285
* @return void
8386
*/
87+
8488
static void test() {
8589
std::array<int, 1> array_1 = {0};
8690
std::array<int, 1> array_2 = {1};
@@ -100,6 +104,7 @@ static void test() {
100104
assert(math::gcd_of_n_numbers::gcd(array_7) == 3450);
101105
assert(math::gcd_of_n_numbers::gcd(array_8) == 1);
102106
}
107+
103108
/**
104109
* @brief Main function
105110
* @return 0 on exit

0 commit comments

Comments
 (0)