Go 实现水仙花数

    技术2023-06-14  69

    package main import ( "fmt" "math" ) func itheima() { for i:=100;i<1000;i++{ d1:=i/100 //百位 d2:=i%100/10 // 十位 d3:=i%10 // 个位 d4:=int(math.Pow(float64(d1),3)) d5:=int(math.Pow(float64(d2),3)) d6:=int(math.Pow(float64(d3),3)) if d4+d5+d6 == i{ fmt.Printf("%v\n",i) } } }

     

    Processed: 0.014, SQL: 9