C++ Program to Find the Number of Digits in a number

By | 25.12.2016

Number of Digits in a number


Write a C++ Program to Find the Number of Digits in a number. Here’s simple Program to Find the Number of Digits in a number in C++ Programming Language.


Here is source code of the C++ Program to Find the Number of Digits in a number. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.


SOURCE CODE : :


/*  C++ Program to Find the Number of Digits in a number  */

#include<iostream>
using namespace std;

int main()
{
    int n,no,a=0;

    cout<<"Enter any positive integer :: ";
    cin>>n;

    no=n;

    while(no>0)
    {
        no=no/10;
        a++;
    }
    cout<<"\nNumber of Digits in a number [ "<<n<<" ] is :: "<<a<<"\n";

   return 0;
}

Output : :


/*  C++ Program to Find the Number of Digit in a number  */

Enter any positive integer :: 12345

Number of Digits in a number [ 12345 ] is :: 5

Process returned 0

Above is the source code for C++ Program to Find the Number of Digit in a number which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

4.4 7 votes
Article Rating
Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
prabhat raushan

sir this program is only count till the 10 digit not more than 10 digit……
if you give the input 14 digit number then output is only 10 . [12345678912345}

Screenshot (1440).png
Dave

just declare int -> long;

The long unity have more byte capacity

Last edited 1 year ago by Dave