-
Notifications
You must be signed in to change notification settings - Fork 0
/
Second highest.cpp
46 lines (39 loc) · 950 Bytes
/
Second highest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
int main()
{
int i,k,n,highest_number,index,second_highest;
printf("How many elements do you want?\n");
scanf("%d",&n);
int a[n];
printf("Please Enter your number\n");
for(i=0;i<n;i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
highest_number=a[0],index=0;
for(i=0;i<n;i++)
{
if(highest_number<=a[i])
{
highest_number=a[i];
index=i;
}
}
printf("\nThe highest number is %d & index number is %d\n",highest_number,index);
second_highest=a[0];
for(i=0;i<n;i++)
{
if(index!=i)
{
if(second_highest<=a[i])
{
second_highest=a[i];
k=i;
}
}
}
index=k;
printf("\nThe second highest number is %d & index number is %d\n",second_highest,index);
return 0;
}