Find largest value of an array – C program

Maximum value of an array – C Program

Write a c program to find the maximum value from an array

Here, we will learn how to find the maximum element from an array in c language program.

An Array is a collection of same data type elements.

For find largest element in array, in below c program first we need to enter five elements in array and using for loop we find the maximum element from existing elements.

#include<stdio.h>

int main()
{
 int a[5],i,max=0;
 printf("Please enter 5 numbers:\n");
 for(i=0;i<5;i++)
  scanf("%d",&a[i]);
 
 max=a[0];
 for(i=1;i<5;i++)
 {
  if(max<a[i])
   max=a[i];
 }
 
 printf("The maximum number of an array =  %d",max);
 return 0;
}

The result of C program example is:

Please enter 5 numbers:
5 16 18 2 3

The maximum number of an array = 18

 

Leave a Reply

Your email address will not be published. Required fields are marked *