Skip to content

Instantly share code, notes, and snippets.

@KhodeN
Last active February 25, 2018 12:02
Show Gist options
  • Save KhodeN/a7998cfb2e7d00f4e5bda050743938af to your computer and use it in GitHub Desktop.
Save KhodeN/a7998cfb2e7d00f4e5bda050743938af to your computer and use it in GitHub Desktop.
Задачка из курса. Заготовка. Читает из stin, пишет в stdout
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
text = strings.TrimSpace(text)
n, err := strconv.Atoi(text)
if err != nil {
fmt.Printf("not a number")
return
}
if n < 1 || n > 20 {
fmt.Printf("not in range 1<=n<=20")
return
}
// сумму квадратов всех целых чисел из промежутка от 1 до n, которые не делятся на 3.
sum := 0
for i := 1; i <= n; i++ {
if i%3 != 0 {
sum += i * i
}
}
fmt.Printf("%d", sum)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment