Go Program to print sum of first 10 natural numbers
In this program, You will learn how to print the sum of the first 10 natural numbers in Go.
55 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
Example: How to print the sum of the first 10 natural numbers in Go
package main
import "fmt"
func main() {
s := 0
for i := 1; i <= 10; i++ {
s = s + i
}
fmt.Println("Sum of natural numbers:", s)
}
Output:
Sum of natural numbers: 55