TutorialEdge

Challenge 20 - Triangular Numbers

Welcome, everyone to the discussion thread for the 19th Go challenge posted to the site :tada:

Feel free to show us how you solved the challenge by posting your solutions below!

package main

import "fmt"

func TriangularNumber(n int) int {
  return (n * (n+1))/2
}

func main() {
  fmt.Println("Returning the 'nth' triangular number")

  number := TriangularNumber(3)
  fmt.Println(number) // '6'

}
1 Like