Обратная последовательность

Messages
1,679
Reaction score
288
Website
tehadm.ru
C-like:
package main

import (
    "fmt"
)

func main() {
    fmt.Println(ReverseSeq(5))
}

func ReverseSeq(n int) []int {
    var arr []int
    for i := n; i >= 1; i-- {
        arr = append(arr, i)
    }
    return arr
}
 
C-like:
func ReverseSeq(n int) []int {
  ans := []int{}
  for n > 0 {
    ans = append(ans, n)
    n--
  }
 
  return ans
}
 
Back
Top