[P1035] Summation problem solution

Here we show you use Goto write this topic:

package main
import "fmt"
func main() {
    a := 1.0
    k := 0.0
    i := 2.0
    fmt.Scan(&k)
    for ; a < k; i++{
        a += 1.0/i
    }
    fmt.Print(i-1)
}

There is a small detail, at the last judgment, when, iat the end of the last cycle added an extra 1, so when output ito-1

Guess you like

Origin www.cnblogs.com/eliclark/p/12367354.html