printf("Enter 5 integers\n");
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
printf("Second max number is %d\n",a);
Try the following algo -
1) Take two variable first and second. Initialize both as INT_MIN (i.e. -infinity)
first = second = INT_MIN
2) Loop through all the elements.
a) If the current element is larger than first, then update first and second.
b) Else if the current element is larger than second then update second
At the end you will get second as second max.
Say you are given two arrays where second array is duplicate with one missing element. What should be the best possible way to find that missing element -
Missing Element: 2