diff options
feat(Week07): Add solutions
1 files changed, 40 insertions, 0 deletions
| -rw-r--r-- | Week07/Exercise15.cpp | 40 |
diff --git a/Week07/Exercise15.cpp b/Week07/Exercise15.cpp new file mode 100644 index 0000000..de89a87 --- /dev/null +++ b/Week07/Exercise15.cpp @@ -0,0 +1,40 @@ +#include <iostream> + +void pow2(unsigned long long* arr, unsigned int size) { + for (unsigned int i = 0; i < size; i++) + arr[i] *= arr[i]; +} + +void mult3(unsigned long long* arr, unsigned int size) { + for (unsigned int i = 0; i < size; i++) + arr[i] *= 3; +} + +bool contains(unsigned long long* arr, unsigned int size, unsigned long long element) { + for (unsigned int i = 0; i < size; i++) + if (arr[i] == element) + return true; + return false; +} + +int main() { + const unsigned long long SIZE = 5; + + unsigned long long input[SIZE], goal; + for (unsigned int i = 0; i < SIZE; i++) + std::cin >> input[i]; + std::cin >> goal; + + for (unsigned long long i = 0; !contains(input, SIZE, goal); i++) { + if (i % 2 == 0) + pow2(input, SIZE); + else + mult3(input, SIZE); + } + + for (unsigned long long i = 0; i < SIZE; i++) + std::cout << input[i] << ' '; + std::cout << std::endl; + + return 0; +} |
