From 390854b00bc38748290db677d4d8bb06aca1c0bf Mon Sep 17 00:00:00 2001 From: kamalbhardwaj Date: Thu, 10 Oct 2019 17:05:40 +0530 Subject: [PATCH] Added Kadane's algo --- cplusplus/max_sum_contiguous_subarray.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 cplusplus/max_sum_contiguous_subarray.cpp diff --git a/cplusplus/max_sum_contiguous_subarray.cpp b/cplusplus/max_sum_contiguous_subarray.cpp new file mode 100644 index 00000000..dbc1f4d8 --- /dev/null +++ b/cplusplus/max_sum_contiguous_subarray.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +int main(){ + int n; + cout<<"Enter no of elements\n"; + cin>>n; + int arr[n]; + cout<<"Enter the elements\n"; + for(int i=0;i>arr[i]; + int start=0,end=0,sum=0,maxsum=0; + for(int i=0;imaxsum){ maxsum=sum; end=i; } } + cout<<"Max sum starts from "<