This is Discussion thread about Subarray with given sum
Discussion About Subarray with given sum
///WHAT IS THE ERROR JUST PASSED 3 TEST CASES
#include
using namespace std;
int main(){
int sum=0,start,ending,found=0;
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int target;
cin>>target;
int i,j,k;
for( i=0;i<n;i++){
sum=0;
for( j=i;j<n;j++){
for( k=j;k<=j;k++){
sum=sum+a[k];
}
if(sum==target){
start=i;
ending=j;
cout<<start<<" "<<ending;
found=1;
break;
}
}
}
if(found==0){
cout<<“None”;
}
return 0;
}