programming-examples/c/Arrays/C Program to Find maximum and second maximum in an array.c

24 lines
562 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*Find maximum and second maximum in an array*/
#include<stdio.h>
#define MAX 100
void main()
{
int arr[MAX],n,i,max,smax;
printf("Enter size of Array: ");
scanf("%d",&n);
printf("Enter %d elements\n",n);
for(i=0; i<n; i++)
{
scanf("%d",&arr[i]);
}
max=arr[0];
for(i=1; i<n; i++)
{
if(arr[i]>max)
{
smax=max;
max=arr[i];
}
}
printf("Maximum : %d Second Maximum:%d ",max,smax);
}