Problem with a program, help please!

My program finds the secondsmallest number in an array, but when user inputs " 1 ; 1 ; 1 ; 2; 3" program gives out 1 instead of 2

Here's the code of the second smallest number part:


smallest = arr[0];
smallind=0;
for(int i =0;i<n;i++)
if(arr[i]<smallest)
{
smallest = arr[i];
smallind = i;
}

if(smallind==0)
{
secondsmallest=arr[1];
}else{
secondsmallest=arr[0];
}
{
for(int i=1;i<n;i++)
{
if(arr[i]<secondsmallest && i!=smallind)
secondsmallest=arr[i];
}
}
If the input is 1 1 1 2 3, then the smallest number is equal to 1, and the second smallest number is also equal to one
Topic archived. No new replies allowed.