Last active
February 25, 2018 12:02
-
-
Save KhodeN/a7998cfb2e7d00f4e5bda050743938af to your computer and use it in GitHub Desktop.
Задачка из курса. Заготовка. Читает из stin, пишет в stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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