# C Program to Find Highest and Second Highest Number

This C Program is to Find the Second Highest Number and Highest Number in an Array,We Keep track of highest element and when an element greater than the current highest element it is swapped so we get the second highest number

```
#include<stdio.h>
void main()
{
int i, n, a, b, num;
a=0;
b=0;
printf("Enter the Maximum amount of Numbers :: ");
scanf("%d", &n);
printf("nn");
for(i=0; i<n; i++)
{
printf("nEnter the Number :: ");
scanf("%d", &num);
if (num > a)
{
b = a;
a = num;
}
else if (num > b)
b = num;
} printf("nn Second Highest Number is :: %d",b);
}
```

Extended Program:Find the Second,Third and Largest Number

```
#include<stdio.h>
main()
{
double num;
int i;
double fbig,secbig,thirdbig=0;
for (i=0;i<6;i++)
{
printf("Enter a Numbern");
scanf("%lf",&num);
if(num>fbig)
{
thirdbig=secbig;
secbig=fbig;
fbig=num;
}
else
secbig=num;
}
printf("The Biggest Number is %lf n The Second Biggest Numer is %lf n The Third Biggest NUmber is %lf n",fbig,secbig,thirdbig);
}
```

OUTPUT

Enter the Maximum amount of Numbers :: 5

Enter the Number :: 2

Enter the Number :: 4

Enter the Number :: 5

Enter the Number :: 8

Enter the Number :: 1

Second Highest Number is :: 5

## Recent Comments