To find the greatest of three numbers in go, these three numbers must be taken as the input from the user, and the output of the program will determine the largest of all the numbers.
To find Greatest of three Numbers in Go Lang
Ask the user to enter three integer values. Read the three integer values in num1, num2, and num3.
The check if num1 is greater than num2 and num3. If statement returns true, then print ‘num1’ as the greatest number.
If statement returns false, then check if num2 is greater than num3 and num1.
second If statements returns false, then print ‘num2’ as the greatest number.
if statement returns false then print ‘num3’ as the greatest number.
Go Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | package main import ( "fmt" ) func main() { fmt.Println("Enter 3 numbers :") var num1 int fmt.Scanln(&num1) var num2 int fmt.Scanln(&num2) var num3 int fmt.Scanln(&num3) /* check the boolean condition using if statement */ if num1>=num2 && num1>=num3 { fmt.Println(num1, "is Largest among three numbers.") /* if condition is true then print the following */ }else if num2>=num1 && num2>=num3 { fmt.Println(num2, "is Largest among three numbers.") }else{ fmt.Println(num3, "is Largest among three numbers") } } |
Output: