-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_sort_sum.cpp
More file actions
41 lines (35 loc) · 830 Bytes
/
array_sort_sum.cpp
File metadata and controls
41 lines (35 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
using namespace std;
int main (){
int n;
cout<<"Enter the array size: ";
cin>>n;
int arr[n];
cout<<"Enter the array: ";
for (int i=0; i<n; i++){
cin>>arr[i];
}
int num, sum=0, counter = 0, flag = 0;
cout<<"Enter number: ";
cin>>num;
cout<<"From intex to intex will give: ";
for (int i=0; i<n; i++){
flag = i;
for (int j=flag;j<n; j++){
sum +=arr[j];
counter++;
if(sum==num){
cout<<i<<" "<<counter-1<<endl;
}
else if(sum>num){
break;
}
else if(sum!=num && flag==n-1){
cout<<"-1";
}
}
counter = 0;
sum=0;
}
return 0;
}