diff options
feat(Week06): Add exercises and solutions
1 files changed, 25 insertions, 0 deletions
| -rw-r--r-- | Week06/Exercise02.cpp | 25 |
diff --git a/Week06/Exercise02.cpp b/Week06/Exercise02.cpp new file mode 100644 index 0000000..24ced19 --- /dev/null +++ b/Week06/Exercise02.cpp @@ -0,0 +1,25 @@ +#include <iostream> + +int main() { + const unsigned int SIZE = 8; + + unsigned int nums[SIZE]; + for (unsigned int i = 0; i < SIZE; i++) + std::cin >> nums[i]; + + unsigned int divisor = nums[0]; + while (divisor > 1) { + bool is_gcd = true; + + for (unsigned int i = 0; i < SIZE && is_gcd; i++) + if (nums[i] % divisor != 0) + is_gcd = false; + + if (is_gcd) break; + divisor--; + } + + std::cout << divisor << std::endl; + + return 0; +} |
