Go 程序查找可被 5 和 11 整除的数字

此 Go 程序用于查找可被 5 和 11 整除的数字,允许用户输入任何数字值。接下来,我们使用 If else 语句检查它是否可以被 5 和 11 整除。如果为 True,则打印第一个语句;否则,打印第二个语句。

package main

import "fmt"

func main() {

    var num int

    fmt.Print("Enter the Number that may Divisible by 5 and 11 = ")
    fmt.Scanln(&num)

    if num%5 == 0 && num%11 == 0 {
        fmt.Println(num, " is Divisible by 5 and 11")
    } else {
        fmt.Println(num, " is Not Divisible by 5 and 11")
    }
}
SureshMac:GoExamples suresh$ go run 5and11.go
Enter the Number that may Divisible by 5 and 11 = 55
55  is Divisible by 5 and 11
SureshMac:GoExamples suresh$ go run 5and11.go
Enter the Number that may Divisible by 5 and 11 = 22
22  is Not Divisible by 5 and 11

Golang 程序查找可被 5 和 11 整除的数字

golang 程序允许输入最大值。接下来,我们使用 for 循环将数字从 1 迭代到 dnum。在循环中,我们使用 If 语句检查数字是否可被 5 和 11 整除。如果为 True,则打印该数字。

package main

import "fmt"

func main() {

    var dnum int

    fmt.Print("Enter the Max Number that may Divisible by 5 and 11 = ")
    fmt.Scanln(&dnum)

    fmt.Print("\nThe List of Numbers that are Divisible by 5 and 11 \n")
    for num := 1; num <= dnum; num++ {
        if num%5 == 0 && num%11 == 0 {
            fmt.Print(num, "\t")
        }
    }
}
Golang program to find number divisible by 5 and 11