add: for statement loop exercises
This commit is contained in:
21
13-loops/exercises/01-sum-the-numbers/main.go
Normal file
21
13-loops/exercises/01-sum-the-numbers/main.go
Normal file
@ -0,0 +1,21 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE: Sum the numbers
|
||||
//
|
||||
// 1. By using a loop, sum the numbers between 1 and 10.
|
||||
// 2. Print the sum.
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// Sum: 55
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
}
|
20
13-loops/exercises/01-sum-the-numbers/solution/main.go
Normal file
20
13-loops/exercises/01-sum-the-numbers/solution/main.go
Normal file
@ -0,0 +1,20 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var sum int
|
||||
for i := 1; i <= 10; i++ {
|
||||
sum += i
|
||||
}
|
||||
fmt.Println("Sum:", sum)
|
||||
}
|
Reference in New Issue
Block a user