Saturday, August 18, 2018

MAXIMUM ELEMENT IN AN ARRAY USING FUNTIONS

  • Problem Description

    Write a program to find the maximum element in an array. 

    Input Format:

    Input consists of n+1 integers. The first integer corresponds to n , the size of the array. The next n integers correspond to the elements in the array. Assume that the maximum value of n is 15.

    Output Format:

    Refer sample output for details.
  • CODING ARENA::
  • #include <stdio.h>
    int main()
    {
      int a,b,i,l=0;
      scanf("%d",&a);
      for(i=0;i<a;i++)
      {
        scanf("%d",&b);
        if(b>l)
        {
          l=b;
        }
      }
      printf("%d is the maximum element in the array",l);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    5
    
    2 3 6 8 1
    
    
    Expected Output
    8 is the maximum element in the array
  • Test Case 2

    Input (stdin)
    7
    
    9 8 7 6 5 4 3
    
    
    Expected Output
    9 is the maximum element in the array

No comments:

Post a Comment