sum of subarrays

 // Online C++ compiler to run C++ program online

#include <iostream>

#include <climits>

using namespace std;


void display(int *arr, int n){

    for(int i=0;i<n;i++){

        cout<<arr[i];

    }

}



int main() {

    int arr[]={4,5,6,7,8,9};

    int n=sizeof(arr)/sizeof(int);

    //cout<<n;

    int max=INT_MIN;

    int sum=0;

    

    for (int i=0;i<n;i++){//strt pointer

        //sum[i]=0;

        for(int j=i;j<n;j++){//end pointer

           for (int k=i;k<=j;k++){//betweeen start to end move and add

               sum=sum+arr[k];

               cout<<arr[k]<<endl;

           }

        }

    }

    cout<<sum;

    //display (arr,n);

    


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings