

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- Golang Program to count the number of nodes in a linked list.
- Write a program in Python to count the number of digits in a given number N
- Write a Golang program to find the sum of digits for a given number
- Java program to Count the number of digits in a given integer
- Golang program to count the number of nodes in a doubly linked list.
- Java Program to Count Number of Digits in an Integer
- Find count of digits in a number that divide the number in C++
- Program to count number of elements in a list that contains odd number of digits in Python
- Golang Program to count the number of flips to convert a given integer to another.
- How to count the number of repeated characters in a Golang String?
- Program to count number of stepping numbers of n digits in python
- Golang Program to find the parity of a given number.
- Count number of digits after decimal on dividing a number in C++
- How to count digits of given number? JavaScript
- C++ Program to Sum the digits of a given number
Advertisements