C Program to Find Second Biggest element in Array

This C Program Find Second Biggest element Array program explains how to find second biggest element in the given array using C language syntax.


#include<stdio.h>
int main()
{
int arr[50],n,i,j=0,first,second;
printf(“Enter Size of Array : “);
scanf(“%d”,&n);
printf(“Enter elements : \n”);
for(i=0 ; i<n ; i++)
{
scanf(“%d”,&arr[i]);
}
first=arr[0];
for(i=1 ; i<n ; i++)
{
if(first<arr[i])
{
first=arr[i];
j=i;
}
}
second = arr[n-j-1];
for(i=1 ; i<n ; i++)
{
if(second<arr[i] && j!=i)
{
second=arr[i];
}
}
printf(“Second biggest element : %d\n”, second);
return 0;
}

Share this