Find out the second highest in array
There is a problem in your code. Assuming that input is [3, 2, 1], the program will work like this.


Set first and second as 3.
Iterate through elements noticing that nothing is larger than 3.
Claim that 3 is the second number.


To fix this, you can do something like this.

if (arr[0] &lt; arr[1]) {
    second = arr[0];
    first = arr[1];
}
else {
    second = arr[1];
    first = arr[0];
}

for (i = 2; i &lt; elems; i++) {
    /* Your code */
}


Also, your program doesn't work well when NaN is involved in first position. This probably doesn't really matter (currently this handles integers, not double floating point numbers), but this may be still relevant for you, as it would require some special code to handle NaN.