-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUBARRAY
51 lines (42 loc) · 964 Bytes
/
SUBARRAY
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
42
43
44
45
46
47
48
49
50
51
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
int main() {
int n;
cout<<"enter the size of arrar"<<endl;
cin>>n;
int A[n];
cout<<"enter the elements in array"<<endl;
for(int i =0;i<n ;i++){
cin>>A[i];
}
cout<<"enter the value of k "<<endl;
int k;
cin>>k;
int j;
for(int i = 0;i<n-k;i++){
int max = 0;
for( j = i; j<i+k ;j++){
cout<<A[j]<<" ";
}
for(int k = i; k<j ;k++){
if(max<A[k]){
max = A[k];
}
}
cout<<"= "<<max;
cout<<endl;
}
for(int i = n-k; i<n ;i++){
cout<<A[i]<<" ";
}
int max;
int f = k;
for(int k = n-f; k<n ;k++){
if(max<A[k]){
max = A[k];
}
}
cout<<"= "<<max;
return 0;
}