#
CODE
include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
int higher=0;
int highest=0;
int counter = 0;
while(counter <10)
{
printf("Enter a number: ");
scanf("%d", &num);
if(num > higher)
{
if(num > highest)
{
higher = highest;
highest = num;
}
else
higher = num;
}
counter += 1;
printf("The two highest numbers are %d and %d\n.", higher,highest);
}
return 0;
}
Try this. It may work better.
QUOTE(browngod2002 @ 20 Sep, 2006 - 01:39 AM)

need to compare ten numbers input from a user and find the two highest. i haver to do this without putting the numbers in an array and then using qsort to sort them.
CODE
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int num;
int higher;
int highest;
int counter = 0;
while(counter <10)
{
printf("Enter a number: ");
scanf{"%d", &num);
if(num > highest)
num =higher;
else
num = highest;
}
printf("The two highest numbers are %d and %d\n.", higher,highest);
system("PAUSE");
return 0;
}
This only works if the numbers are in a special order. Try rearranging the order of entry, Largest before next largest. Next largest before largest.
Warren
This post has been edited by Dark_Nexus: 22 Sep, 2006 - 01:36 PM