We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e0d953e commit 2243e32Copy full SHA for 2243e32
11SubarraywithGivenSum.cpp
@@ -0,0 +1,30 @@
1
+
2
+#include <bits/stdc++.h>
3
+using namespace std;
4
+//SUBARRAY WITH GIVEN SUM
5
+int main() {
6
+ int n=5;
7
+ int s=6;
8
+ int flag=0;
9
+ int i,j;
10
+ int arr[n]={1,2,3,7,5};
11
+ for( i=0;i<n;i++){
12
+ int sum=arr[i];
13
+ for(j=i+1;j<n;j++){
14
+ sum=sum+arr[j];
15
+ if(sum==s){
16
+ flag=1;
17
+ break;
18
+ }
19
+ if(sum>s){
20
21
22
23
+ if(flag==1){
24
+ cout<<i+1<<" "<<j+1;
25
26
27
28
29
+ return 0;
30
+}
0 commit comments