You might try this solution which has an array of 2 integers to contain the answer. While traversing the a[] , if the value is greater than the 1 in your answer's array, replace it in the answer's array. And then compare values in the answer to decide which is the greatest. Repeat this until a[] traversing is done and you will get the answer.
Here's the guide code.
-
int answer[2] = {0,0} ;
-
int a[]={0,100,5,2,3,200}
-
-
for(int i=0 ; i < a. length; i++)
-
{
-
if(answer[1] < a[i])
-
{
-
answer[1] = a[i];
-
if(answer[0] < answer[1])
-
{
-
int temp = answer[1];
-
answer[1] = answer[0];
-
answer[0] = temp;
-
}
-
}
-
}
-
-
return answer;
-
hope this helps. I'm not sure with c syntax but the algo should be fine. :)