doushichun9409 2013-12-25 15:32
浏览 11
已采纳

去操场#23返回问题

http://tour.golang.org/#23

package main

import (
    "fmt"
    "math"
)

func pow(x, n, lim float64) float64 {
    if v := math.Pow(x, n); v < lim {
        return v

    } else {
        fmt.Printf("%g >= %g
", v, lim)
    }
    // can't use v here, though
    return lim
}

func main() {
    fmt.Println(
        pow(3, 2, 10),
        pow(3, 3, 20),
    )
}

why the output is

27 >= 20
9 20

but not

9
27 >= 20 20
  • 写回答

2条回答 默认 最新

  • dtpw54085 2013-12-25 16:00
    关注

    the code for your expected result is

        func main(){
            fmt.Println(pow(3, 2, 10))
            fmt.Println(pow(3, 3, 20))
        }
    

    After all "pow" functions in "fmt.Println" are called, "fmt.Println" prints the results of pows

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)