If Any Required Program Please Ask In Comment I Will Help You(any Program in JAVA or C++) . . THANKS FOR VISITING MY BLOG!

If U LIKE MY PROFILE RAISE YOUR HAND IF U NOT RAISE UR STANDARD. Powered by Blogger.

Sunday, October 21, 2018

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