Lucky Number

QUESTION

Aryan wants to win a lottery worth Rs 5 crores.The challenge given to Aryan is to find a number from group of numbers(array) which is initially increasing and then decreasing.Since Aryan is not good in numbers he seeks your help.Help Aryan to win the lottery.\n\nInput:\nThe first line contains size of the array.\nThe second line contains the elements of the array.\n\nOutput:\nThe output contains the winning lottery number.

“TESTCASE_1”: “11\n8 10 20 80 100 200 400 500 3 2 1\n###—###SEPERATOR—###—\n500”, “TESTCASE_2”: “7\n1 3 50 10 9 7 6\n###—###SEPERATOR—###—\n50”, “TESTCASE_3”: “5\n120 100 80 20 0\n###—###SEPERATOR—###—\n120”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>
 
int findMaximum(int arr[], int low, int high)
{
   int max = arr[low];
   int i;
   for (i = low; i <= high; i++)
   {
       if (arr[i] > max)
          max = arr[i];
   }
   return max;
}
 
/* Driver program to check above functions */
int main()
{
  int n,i;
  scanf("%d",&n);
  int arr[n];
  for(i=0;i<n;i++)
    scanf("%d",&arr[i]);
  
   printf("%d", findMaximum(arr, 0, n-1));
 
   return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro