Skip to content

Instantly share code, notes, and snippets.

@jtprogru
Created May 14, 2022 16:50
Show Gist options
  • Save jtprogru/b57feea847b7b6c8d04aba1dd1239339 to your computer and use it in GitHub Desktop.
Save jtprogru/b57feea847b7b6c8d04aba1dd1239339 to your computer and use it in GitHub Desktop.
По данному числу N распечатайте все целые значения степени двойки, не превосходящие N, в порядке возрастания. Вводится натуральное число. Выведите ответ на задачу.
package main
import (
"fmt"
"math"
)
func main() {
var n int
var outputStr string
_, _ = fmt.Scan(&n)
for i := 0; i <= n; i++ {
x := int(math.Exp2(float64(i)))
if x > n {
break
}
outputStr += fmt.Sprintf("%d ", x)
}
fmt.Println(outputStr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment