Q).
=> Coding:
#include<iostream>
using namespace std;
int subsetSum(int a[],int len){
int sum=0,maxSum=0;
for(int i=1;i<=len;i++){
for(int j=0;j<=len-i;j++){
for(int k=0;k<i;k++){
sum=sum+a[j+k];
}
if(sum>maxSum){
maxSum=sum;
}
sum=0;
}
}
return maxSum;
}
int main(){
int n;
cout<<"Enter the size of the array\n";
cin>>n;
int a[n];
cout<<"Enter Array size : \n";
for(int i=0;i<n;i++){
cin>>a[i];
}
int r=subsetSum(a,n);
cout<<"result "<<r<<endl;
}
=> Output:
Comments
Post a Comment