- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to Count the Number of Digits in a Number
Suppose the number is: 123456
Count of digits in the given number is: 6
To count the number of digits in a number, we can take following
Steps
- Take the value of the integer and store in a variable.
- Using a while loop, get each digit of the number and increment the count each time a digit is obtained.
- Print the number of digits in the given integer.
Example
package main import "fmt" func main(){ var n int fmt.Print("Enter the number: ") fmt.Scanf("%d", &n) count := 0 for n >0 { n = n/10 count++ } fmt.Printf("The number of digits in the given number is: %d", count) }
Output
Enter the number: 123456 The number of digits in the given number is: 6
- Related Articles
- Write a program in Python to count the number of digits in a given number N
- Java program to Count the number of digits in a given integer
- Golang Program to count the number of nodes in a linked list.
- Golang Program to Count number of leaf nodes in a tree
- Golang Program to Count number of lines present in the file
- Java Program to Count Number of Digits in an Integer
- Swift Program to Count Number of Digits in an Integer
- Haskell Program to Count Number of Digits in an Integer
- Kotlin Program to Count Number of Digits in an Integer
- Golang program to count the number of nodes in a doubly linked list.
- Write a Golang program to find the sum of digits for a given number
- Program to count number of elements in a list that contains odd number of digits in Python
- Program to count number of stepping numbers of n digits in python
- Find count of digits in a number that divide the number in C++
- Golang Program to count the number of flips to convert a given integer to another.

Advertisements