Find leader in array in c#
Find leader in array in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Brijesh RathorPosted Nov 17, 2016, 5:50 AM
MayankPosted Nov 17, 2016, 5:42 AM
using namespace std;
/*C++ Function to print leaders in an array */
void printLeaders(int arr[], int size)
{
for (int i = 0; i < size; i++)
{
int j;
for (j = i+1; j < size; j++)
{
if (arr[i] <= arr[j])
break;
}
if (j == size) // the loop didn't break
cout << arr[i] << " ";
}
}
/* Driver program to test above function */
int main()
{
int arr[] = {16, 17, 4, 3, 5, 2};
int n = sizeof(arr)/sizeof(arr[0]);
printLeaders(arr, n);
return 0;
}
I u think it resolve your query please mark as answer.
JohnPosted Nov 17, 2016, 5:08 AM
voidprintLeaders(intarr[],intsize){for(inti = 0; i < size; i++){intj;for(j = i+1; j < size; j++){if(arr[i] <= arr[j])break;}if(j == size)// the loop didn't breakconsole.write arr[i];}}