add: for statement loop exercises
This commit is contained in:
38
13-loops/exercises/03-sum-up-to-n/main.go
Normal file
38
13-loops/exercises/03-sum-up-to-n/main.go
Normal file
@ -0,0 +1,38 @@
|
||||
// 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 up to N
|
||||
//
|
||||
// 1. Get two numbers from the command-line: min and max
|
||||
// 2. Convert them to integers (using Atoi)
|
||||
// 3. By using a loop, sum the numbers between min and max
|
||||
//
|
||||
// RESTRICTIONS
|
||||
// 1. Be sure to handle the errors. So, if a user doesn't
|
||||
// pass enough arguments or she passes non-numerics,
|
||||
// then warn the user and exit from the program.
|
||||
//
|
||||
// 2. Also, check that, min < max.
|
||||
//
|
||||
// HINT
|
||||
// For converting the numbers, you can use `strconv.Atoi`.
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// Let's suppose that the user runs it like this:
|
||||
//
|
||||
// go run main.go 1 10
|
||||
//
|
||||
// Then it should print:
|
||||
//
|
||||
// 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
}
|
Reference in New Issue
Block a user