Create a recursive c++ function to fill up an array and make sum of all digit. you have to create different recursive function for fill up and to make sum.
#include<iostream>
using namespace std;
void array_recursive(int array[],int n)
{
if (n-1>=0)
{
cout<<"Enter elements into the array:\n";
cin>>array[n];
n--;
array_recursive(array,n);
}
}
int sum_array(int array[],int n)
{
if (n= =0)
{
return array[0] ;
}
return array[n]+sum_array(array,n-1);
}
int main( )
{
int n;
cout<<"Enter the size of an array:\n";
cin>>n;
int array[n];
array_recursive(array,n);
cout<<"Printing Recursive Data\n";
for(int i=n; i>0; i--)
{
cout<<array[i]<<"\n";
}
cout<<"the sum is: "<<sum_array(array+1,n-1)<<endl;
}