Finding the maximum and minimum numbers in a file containing 20 integers
I am having trouble with writing a program that is to find the smallest and largest numbers from a file containing 20 integers. I started it but i cant seem to get it to work. Can someone please help me.
Code:
#include <stdio.h>
int main (void)
{
int counter = 0;
int num1;
int num2;
int largest;
int smallest;
while (counter < 20)
{
scanf("%d%d", &num1, &num2);
if (num1 > num2)
largest = num1;
if (num1 < num2)
smallest = num1;
counter++;
}
printf("%d %d", largest, smallest);
return 0;
}