Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  Counts the number of digits in a given number
Language: C/C++
Code:
#include<stdio.h>

main()
{
int n,i;
int res,addones=1;
int n1,n2;

printf("Enter a positive number ");
scanf("%d",&n);

res=n/10;
if(res == 0)
printf("Number of digits is %d\n",1);

else
{
n1=1;
n2=10;

for(i=1;i<10000;i++)
{
if((res >= n1)  && (res < n2))
{
addones+=1;
goto l1;
}
addones+=1;
n1*=10;
n2*=10;
}
l1:printf("Number of digits is %d\n",addones);
}
}


          
Comments: