0

I have a program in which tells me the highest number and the lowest number. ( i am using a loop for the highest and lowest)

I need to get the second highest and second lowest. without an array

i was wondering if i could find that within the same loop?

i already have the code for the largest and smallest
it just wont let me get the second largest and second smallest.

The user enters 30 numbers, find the second largest and second smallest

for(int i =0; i<30 ; i++)
if(input>maxi)
maxi=input;
if (input <mini)
mini=input;
//finds max and min

Edited by peter_budo: Correcting code tags

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Ezzaral
0

sure you can, as long as you keep an eye out for the biggest and smallest as well ..

(just piece of the logic, not actual code)

a = smallest, b = second smallest, c = input ...

if ( a > c )
b = a and a = c
else if ( b > c )
b = c

and about the same for biggest and second biggest

0

Then start a thread of your own with an actual question instead of hijacking someone else's old thread.

Closed.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.