Finding smallest and second smallest integer and largest and second largest integer
I am writing a progam that finds the smallest and second smallest integer and also the largest and second to largest integer in a list of 20 integer. The program is to read them from a file. I figured out how to find the first smallest and first largest number but i have no idea how to find the second smallest and second largest number. Can someone please help me.
Code:
#include <stdio.h>
int main (void)
{
int counter;
int num1;
int num2;
int largest = 0;
int smallest;
for (counter = 0; counter < 20; counter++);
{
scanf("%d", &num1);
if(num1 < smallest)
smallest = num1;
}
for (counter = 0; counter < 20; counter++)
{
scanf("%d", &num2);
if(num2 > largest)
largest = num2;
}
printf("\nSmallest: %d", smallest);
printf("\nLargest: %d", largest);
return 0;
}