Find Number of Digits of Any Numbers in C

Advertisements

Prev Tutorial Next Tutorial

Calculate Number of Digits of Any Numbers in C

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

  • Enter +ve Number
  • Enter -ve Number
  • Enter zero

Find number of Digits

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

Find Number of Digits of Any Numbers in C

#include<stdio.h>
#include<conio.h>

void main()
{
int no,a=0;
clrscr();
printf("Enter any number: ");
scanf("%d",&no);
while(no>0)
{
no=no/10;
a++;
}
printf("Number of digits in given number is: %d",a);
getch();
}

Output

Enter any number: 650
Number of digits in given number is: 3

Find number of digits

This code is satisfy all the above three conditions.

Calculate Number of Digits of Any Numbers in C

#include<stdio.h>
#include<conio.h>

void main()
{
int no,a=0;
clrscr();
printf("Enter any number: ");
scanf("%d",&no);
if(no<0)
{
no=no * -1; // convert -ve number into +ve number
}
else if(no==0)
{
no=1;
}
while(no>0)
{
no=no/10;
a++;
}
printf("Number of digits in given number is: %d",a);
getch();
}

Output

Enter any number: -650
Number of Digits in given number is: 3

Prev Tutorial Next Tutorial

Advertisements

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

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

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