Count number of Digits of an Integer in C++

Advertisements

Reverse Number in C++ Fionacci Series in C++

C++ Program to Find number of Digits from any number

Any number is a combination of digits, like 342 have three digits and 4325 have four digits. For calculating the digits of any number user have three possibilities to input values.

  • Enter +ve numbers
  • Enter -ve numbers
  • Enter zero

This code is correct when user enter +ve numbers Only.

Example

#include<iostream.h>
#include<conio.h>

void main()
{
int no,a=0;
clrscr();
cout<<"Enter any num : ";
cin>>no;
while(no>0)
{
no=no/10;
a++;
}
cout<<"\n no. of digits in given number is: "<<a;
getch();
}

Output

Enter any num : 650
no. of digits in given number is : 3

This code is satisfy all the above three conditons.

C++ program to count number of digits of an integer

#include<iostream.h>
#include<conio.h>

void main()
{
int no,a=0;
clrscr();
cout<<"Enter any num : ";
cin>>no;
if(no<0)
{
no=no * -1;
}
else if(no==0)
{
no=1;
}
while(no>0)
{
no=no/10;
a++;
}
cout<<"\n no. of digits in given number is: "<<a;
getch();
}

Output

Enter any num : -650
no. of digits in given number is : 3

Reverse Number in C++ Fionacci Series in C++

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements