How to find lead numbers in an array

Lead numbers in an array are those numbers which are greater than all the elements to its right side. For example consider an array {8,20,1,3,4,2}. In the array the lead numbers are 20,4 and 2.


Write a program to find and print all the leaders from an user entered array.

#include<iostream> 

using namespace std; 

int main() 

int n,i,j,arr[10];

cout<<"Enter the Size of the Array";

cin>>n;

cout<<"Enter the Array Elements";

for (i=0;i<n;i++)

{

    cin>>arr[i];

}

for (int i = 0; i < n; i++) 

int j; 

for (j = i+1; j < n; j++) 

if (arr[i] < arr[j]) 

break; 

}  

if (j == n) 

cout << arr[i] << " "; 

}

return 0; 


Comments