Header Ads Widget

Count number of digit in a number in C++

 

 Count number of digit in a number in C++

Given a number , write a program to count number of digits in a number . 

Sample input

78563

Sample output

5

 Count number of digit in a number in C++

The objective of the code is to find the number of digits in a given number in c++ .

Code(C++):-

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

Output:-

Enter a number
78536
Number of digits is 5

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-