To find maximum number between every two consecutive elements in Array also print final maximum number

  •  Code:- 
#include<iostream>
#include<climits>
using namespace std;
int main(){
   long int n ;
    long int maximum=INT_MIN;
    long int maxi =INT_MIN+1;
    cout<<"Enter size of array : ";
    cin>>n;
   long int arr[n];
    for(long int i =0,j=1;i<n,j<n+1;i++,j++){
        cout<<"enter no"<<j<<": ";
        cin>>arr[i];
    }
    for(long int i =0,j=1;i<n+1,j<n;i++,j++){
        maximum=max(arr[i],arr[j]);
        maxi=max(arr[i],arr[j]);
        cout<<"from "<<arr[i]<<" & "<<arr[j]<<" : " <<maxi<<" is maximum"<<endl;
    }
    long int great=max(arr[0],arr[n-1]);
    cout<<"from "<<arr[n-1]<<" & "
    <<arr[0]<<" : "<<great<<"is maximum"<<endl;
    cout<<"the final maximum number is "<<maximum<<"\n";
    return 0;
}


  • Output:-



Comments

Popular posts from this blog

To do addition of all the Elements of Array in C++

A program to Search element in array , and if repeated so at which location it is present and how many time the number is repeated

Take n no. Of elements and arrange them in Ascending & Descending Order