This code is supposed to take in ten numbers from the user and print out the highest two numbers. I think I'm having a problem with the last buffer not being cleared when I enter 1 thru 10. Here is what I have so far:
#include <stdio.h>
#include <stdlib.h>
int number=0, largest=0, sec_largest=0, i;
int main (void)
{
int c;
clrscr();
for (i=1;i<10;i++)
{
scanf("%d\n",&number);
if (largest<number)
{
sec_largest=largest;
largest=number;
}
if ((sec_largest<number)&&(largest>number))
sec_largest=number;
}
printf("The largest number is %d and the second largest is %d",largest,sec_largest);
return 0;
}
When I enter 1-10, it thinks 9 and 8 are the two largest. Thanks in advance for help.