Max sum of subarray
// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int max_sum(int*arr, int n){
int sum=0;
int m=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
sum=0;
for(int k=i;k<j;k++){
sum=sum+arr[k];
m=max(sum,m);
}
}
}
return m;
}
int main() {
int arr[10]={2,3,-8,7,-1,3,2};
int n=8;
cout<<max_sum(arr,n);
return 0;
}
Comments
Post a Comment