Monday, March 17, 2014

Find Maximum Element In Array

Share Post:
#include <stdio.h>
#include <conio.h>

int main()
{
  int array[100], max, size, i, loc = 1;

  printf("Input number of elements in array\n");
  scanf("%d", &size);


  printf("Input %d integers\n", size);

  for (c = 0; c < size; c++)
    scanf("%d", &array[c]);

  max = array[0];

  for (i = 1; i < size; i++)
  {
    if (array[i] > max)
    {
       max  = array[i];
       loc = i+1;
    }
  }

  printf("Maximum element is at location %d and the value is %d.\n", loc, max);
  return 0;
}

0 comments:

Post a Comment