C++ Array with reccursion [closed]

  arrays, c++, recursion

I need help with a program that needs 3 numbers to start an array and the next number of the array is the sum of the previous 3. For example: 1, 1, 1, 3, 5, 9, 17,…
It needs to be done with recursion. I tried to do something but I am getting a return value of 3221225725. Here is my attempt:

#include<iostream>
using namespace std;

int arr(int a, int b, int c){
    return a+b+c+arr(a=b, b=c, c=a+b+c);
}
int main(){
    int a, b, c;
    cin>>a>>b>>c;
    cout<<arr(a, b, c);
}

Source: Windows Questions C++

LEAVE A COMMENT