Count number of Digits of an Integer in C++

Google 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 Advertisements

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

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

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

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs