0
Code to get second largest among three .... considering d case dat 2 can b equal.....
2 Respostas
+ 2
let's suppose your numbers are a, b, and c.
int a, b, c;
int max1, max2;
max1 = max2 = -1;
if(a > max1) {
max2=max1;
max1=a;
}else if(a > max2) max2 = a;
if(b > max1) {
max2=max1;
max1=b;
}else if(b > max2) max2 = b;
if(c > max1) {
max2=max1;
max1=c;
}else if(c > max2) max2 = c;
The maximum values is max1 and the second largest is max2. Keep in mind max1 and max2 must have an initial value lower than all 3 numbers, here, i supposed all numbers are integers, greater than 0. Hopefully this helps
0
tysm