1234567891011121314151617
void fillInFibonacciNumbers(int result[], int length) { result[0] = 0; result[1] = 1; for (int i = 2; i < length; i++) { result[i] = result[i-1] + result[i-2]; } } void printArray(int arr[],int length) { for (int i = 0; i < length; i++) { std::cout << arr[i] << endl; } }
123456
constexpr int length = 10; int result[length]; fillInFibonacciNumbers(result, 10); printArray(result, 8); //gives output 0,1,1,2,3,5