Recursion 8 : Maximum Element in Array

Description:

Write a program to find the maximum element in an array using recursion. Input and Output Format: Input consists of n+1 integers. Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. Test Case 1 Input (stdin) 6 2 5 1 7 4 2 Expected Output Maximum element in the array is 7 Test Case 2 Input (stdin) 4 9 8 7 6 Expected Output Maximum element in the array is 9

Program :

#include <stdio.h>

 

int main()

{

  int array[100], maximum, size, c;

  scanf("%d", &size);

 

  for (c = 0; c < size; c++)

    scanf("%d", &array[c]);

 

  maximum = array[0];

 

  for (c = 1; c < size; c++)

  {

    if (array[c] > maximum)

    {

       maximum = array[c];

    }

  }

 

  printf("Maximum element in the array is %d",maximum);

  return 0;

}