Created
May 13, 2022 15:42
-
-
Save jtprogru/1dc7efcb98f7c6dab86464fb2d56a92b to your computer and use it in GitHub Desktop.
Цифровой корень натурального числа — это цифра, полученная в результате итеративного процесса суммирования цифр, на каждой итерации которого для подсчета суммы цифр берут результат, полученный на предыдущей итерации. Этот процесс повторяется до тех пор, пока не будет получена одна цифра. Например цифровой корень 65536 это 7, потому что 6+5+5+3+6…
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" | |
| func main() { | |
| var inputNumber int | |
| _, _ = fmt.Scan(&inputNumber) | |
| fmt.Println(Dr(inputNumber)) | |
| } | |
| func Dr(num int) int { | |
| if num <= 9 { | |
| return num | |
| } else if num%9 == 0 { | |
| return 9 | |
| } | |
| return Dr(num % 9) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment