Check The Programming Section
Using if-else ladder with logical AND (&&) operator can be used to compare more than two values with an if condition. This program also checks the equality between two or three numbers. For example,
num1 = 11
num2 = 12
num3 = 13
In the above example, num1 need to compared with num2 first using greater than (>) relational operator and further num1 also need to compare with num3. Similarly we need to compare num2 with num3. The required code is as follows:
At source line 6, if(num1>num2 && num1>num3) num1 is compared with num2 and num3, if both the condition is true then it prints num1 is the largest. For example, 12 11 10, 12 will printed as largest.
If three numbers 11 13 12 is given as input, then condition written at line 8 else if(num2>num3) is become true and 13 is printed as largest.
If three numbers 11 12 13 is given as input then both the conditions written at line 6 and 8 is false. So else part get executed and the last else part inside the body of the else at line 16 get executed and prints 13 is largest.
If three numbers 12 12 11 is given as input, at first, condition written at line 8 else if(num2>num3) is true and then condition written at line 9 if(num1==num2) also become true and it prints num1 and num2 both is largest.
If three numbers 12 11 12 is given as input, program control goes to the else part and then condition written at line 14 else if(num1==num3) is become true at print num1 and num3 both are equal and largest.
If three numebers 11 12 12 is given as input, then condition written at line 15 else if(num2==num3) is become true and it prints num2 and num3 both are largest and equal.
If three numbers 12 12 12 is given as input, then condition written at line 13 if(num1==num2 && num1==num3) become true and prints all numbers are equal.