Home » NO IDEA » Number of digits in a number

Number of digits in a number

Blog Stats

  • 14,863 hits
January 2013
M T W T F S S
« Dec   Mar »
 123456
78910111213
14151617181920
21222324252627
28293031  

This program is to find the number of digits in the given number like counting the string length quite same but differ in the data types .This idea can be extended to write you own counting the number of characters in the string

//Number of the digits in a number
#include<stdio.h>
int main()
{
int num,sum,count=0,r;
sum=0;
printf("\n Enter the number ");
scanf("%d",&num);
while(num)
{
r=num%10;
sum=sum+r;
num=num/10;
count++;
}
printf("\n The Number of the digits %d",count);
return 0;
}
Sample output:
Enter a number: 1234567
Total digits is:  7
Advertisements

1 Comment

  1. […] Number of digits in a number […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: