Count number of digits in C++ - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Friday, June 12, 2020

Count number of digits in C++


C++ PROGRAM TO COUNT THE NUMBER OF DIGITS IN AN INTEGER


Sample Test Case    :    Enter a Number :   2345

Sample Output        :    Number of digits in the given number is 4 

               

CODE 


#include <iostream>
using namespace std;
int main()
{
    int num,digit=0;
    cout<<"Enter a Number :";
    cin>>num;
    while(num!=0)
    {
        num/=10;
        digit++;
    }
    cout<<"Number of digits in given number is "<<  digit;
    return 0;
}

No comments:

Post a Comment