View All C Programs

 Previews Example  View All C Programs Next Example 

Program to find largest number in array in C

This program to find largest number in array. Array is a collection of similar types element. We can find maximum or minimum element in an array by using comparison operator. Traversing all the elements and comparing these elements pair wise one by one.
#include <stdio.h>
#include <conio.h>
   main()
{
     int mat[20];
     int s,max;
     printf("\nSize of your Array is : ");
     scanf("%d",&s);
     printf("\nEnter your %d element of an array : \n", s);

     for(int i=0;i < s;i++)
     {
          scanf("%d",&mat[i]);
     }
     max=mat[0];

     for(int i=1;i < s;i++)
     {
          if(max < mat[i])
          max = mat[i];
     }

     printf("\nMaximum value element from given %d element is : %d",s,max);
     getch();
     return 0;
} 
Result
Size of your Array is : 5
Enter your 5 element of an array :
10
20
60
90
70
maximum value element from given 5 element is : 90