void taoMang(int arr[], int n){
srand(time(0));
for(int i = 0; i < n; i++)
cin >> arr[i];
// arr[i] = rand()%100;
}
void xuatMang(int arr[], int n){
for(int i = 0; i < n; i++)
cout << arr[i] << " ";
}
int timMax(int arr[], int n){
if(n == 1) return arr[n-1];
else if(arr[n-1] > timMax(arr, n-1))return arr[n-1];
else return timMax(arr, n-1);
}
int timMaxLienTiep(int arr[], int n){
if(n == 2) return arr[n-1]+arr[n-2];
else{
int max = timMaxLienTiep(arr, n-1);
if(max > arr[n-1]+arr[n-2]) return max;
else return arr[n-1]+arr[n-2];
}
}
bool isMangTang(int arr[], int n){
if(n == 1) return true;
if(arr[n-1] < arr[n-2]) return false;
else isMangTang(arr, n-1);
}
void chen(int arr[], int &n, int x, int k){
if(k <= n){
int tg = arr[k];
arr[k] = x;
chen(arr, n, tg, k+1);
}else n++;
}
int timX(int arr[],int n, int x){
if(n < 0) return -1;
if(arr[n-1] == x) return n-1;
else return timX(arr, n-1, x);
}
void xoa(int arr[], int &n, int k){
if(k < n){
arr[k] = arr[k+1];
xoa(arr, n, k+1);
}else n--;
}
main(){
int arr[100];
int n;
int x, k;
cout << "Nhap n: "; cin >> n;
taoMang(arr, n);
xuatMang(arr, n);
cout << "\nGia tri max: " << timMax(arr,n);
cout << "\nGia tri Tong max liên tiep: " << timMaxLienTiep(arr,n);
if(isMangTang(arr, n))
cout << "\nArr la mang tang: ";
else cout << "\nArr la mang khong tang.";
cout << "\n Nhap x va k: "; cin >> x >> k;
chen(arr, n, x, k);
xuatMang(arr, n);
sapXep(arr, n);
cout <<"\n Sau khi sap xep: " << endl;
xuatMang(arr, n);
}