PROGRAM TO GET SUM OF ARRAY ELEMENTS using RECURSION.
#include <iostream>>
#include <conio.h>
using namespace std;
long Sum(int *Arr, int No);
int main()
{
int Size = 10;
int *Arr = new int[Size];
cout << "Enter Elements Of Array is: " << endl;
for(int I =1; I <=Size; I++)
{
Arr[I] = I;
cout << Arr[I] << endl;
}
cout <<"\nSum of Array is: " << Sum(Arr, Size) << endl;
getch();
return 0;
}
long Sum(int *Ptr, int No)
{
long Result;
if(No <= 0)
return 0;
Result = Ptr[No] + Sum(Ptr, No -1) ;
return Result;
}
0 comments:
Post a Comment