Adding 2nd assignment - recursion

This commit is contained in:
Christopher Sanden
2025-10-24 16:30:19 +02:00
parent 08a6b25df7
commit f94a8a4409
5 changed files with 266 additions and 15 deletions

View File

@@ -0,0 +1,33 @@
#ifndef FUNDAMENTAL_RECURSION_UTILS_H
#define FUNDAMENTAL_RECURSION_UTILS_H
#include <string>
#include <chrono>
void printNaturalNumber(int n);
int calculateFactorial(int n);
int power(int base, int exp);
int fibonacci(int n);
int countOccurrences(const std::string& s, char c);
int findLargestElement(const int arr[], int size);
void traverseAsciiTable(char start, char end);
// Helpers partially generated by ChatGPT
void fillRandomArray(int arr[], int size, int minVal, int maxVal);
std::string makeRandomString(int len, char minChar, char maxChar);
int countOccurrences_index(const std::string& s, char c, int index);
template<typename F, typename... Args>
double time_ms(F&& f, Args&&... args)
{
auto t0 = std::chrono::high_resolution_clock::now();
(void)std::forward<F>(f)(std::forward<Args>(args)...);
auto t1 = std::chrono::high_resolution_clock::now();
return std::chrono::duration<double, std::milli>(t1 - t0).count();
}
#endif //FUNDAMENTAL_RECURSION_UTILS_H