Go程序查找三个数字中的最大值

这个Go程序使用Else If语句来查找三个数字中的最大值。在Else if语句中,我们使用了逻辑与运算符来分隔两个条件。

  • a > b && a > c – 检查a是否大于b和c。如果为True,则a是最大的。
  • else if b > a && b > c – 检查b是否大于a和c。如果为True,则b是最大的。
  • else if c > a && c > b – 检查c是否大于a和b。如果为True,则c是最大的。否则,它们中的任何一个都相等。
package main

import "fmt"

func main() {

    var a, b, c int

    fmt.Print("\nEnter the Three Numbers to find Largest = ")
    fmt.Scanln(&a, &b, &c)

    if a > b && a > c {
        fmt.Println(a, " is Greater Than ", b, " and ", c)
    } else if b > a && b > c {
        fmt.Println(b, " is Greater Than ", a, " and ", c)
    } else if c > a && c > b {
        fmt.Println(c, " is Greater Than ", a, " and ", b)
    } else {
        fmt.Println("Either of them are Equal ")
    }
}
Go Program to find Largest of Three Numbers

Go程序查找三个数字中的最大值。

此Golang程序使用算术运算符和逻辑运算符来打印三个数字中的最大值。

package main

import "fmt"

func main() {

    var a, b, c int

    fmt.Print("\nEnter the Three Numbers to find Largest = ")
    fmt.Scanln(&a, &b, &c)

    if a-b > 0 && a-c > 0 {
        fmt.Println(a, " is Greater Than ", b, " and ", c)
    } else {
        if b-c > 0 {
            fmt.Println(b, " is Greater Than ", a, " and ", c)
        } else {
            fmt.Println(c, " is Greater Than ", a, " and ", b)
        }
    }
}
SureshMac:Goexamples suresh$ go run LargestofThree2.go

Enter the Three Numbers to find Largest = 3 5 2
5  is Greater Than  3  and  2
SureshMac:Goexamples suresh$ go run LargestofThree2.go

Enter the Three Numbers to find Largest = 19 2 27
27  is Greater Than  19  and  2
SureshMac:Goexamples suresh$ go run LargestofThree2.go

Enter the Three Numbers to find Largest = 22 7 20
22  is Greater Than  7  and  20