#include <stdio.h>
#define MAX 5
int main()
{
int arr[MAX], i, larg1, larg2, temp;
printf("Enter %d the numbers \n", MAX);
for (i = 0; i < MAX; i++)
{
scanf("%d", &arr[i]);
}
printf("Input integer are \n");
for (i = 0; i < MAX; i++)
{
printf("%5d", arr[i]);
}
printf("\n");
larg1 = arr[0];
larg2 = arr[1];
if (larg1 < larg2)
{
temp = larg1;
larg1 = larg2;
larg2 = temp;
}
for (i = 2; i < 4; i++)
{
if (arr[i] >= larg1)
{
larg2 = larg1;
larg1 = arr[i];
}
elseif (arr[i] > larg2)
{
larg2 = arr[i];
}
}
printf("\n%d is the first largest number in array\n", larg1);
printf("%d is the second largest number in array \n", larg2);
printf("\n Average of %d and %d = %d \n", larg1, larg2,(larg1 + larg2) / 2);
}
output is below:-
