Created
March 10, 2020 17:11
-
-
Save akshaybharambe14/30956308967fc4da88b8153ef80571ce to your computer and use it in GitHub Desktop.
Function to count digits in a number in golang
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 ( | |
"fmt" | |
) | |
func main() { | |
fmt.Println(CountDigits(1234454666)) | |
} | |
func CountDigits(i int64) (count int64) { | |
for i > 0 { | |
i = i / 10 | |
count++ | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment