Created
May 12, 2022 20:44
-
-
Save jtprogru/686f79722e8a7b2214d6af169470efa4 to your computer and use it in GitHub Desktop.
Дано трехзначное число. Найдите сумму его цифр. На вход дается трехзначное число. Выведите одно целое число - сумму цифр введенного числа.
This file contains hidden or 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 ( | |
"fmt" | |
"strconv" | |
) | |
func main() { | |
var inputNumber string | |
var counter int | |
_, _ = fmt.Scan(&inputNumber) | |
for _, char := range inputNumber { | |
d, _ := strconv.Atoi(string(char)) | |
counter += d | |
} | |
fmt.Println(counter) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment