Get length of any integer number in C Programming

We will get the total length of any integer number from here. For example see the following table.



Integer
Length
9
1
1
1
12
2
654
3
546
3
656468
6
3187
4
65484
5


We use a function length for this. Try the bellow.

#include<stdio.h>
main()
{
v2();
}

v2()
{
    int a,b;
    printf("Enter integer:\n");
    scanf("%d",&a);
    b = lenght(a);
    printf("Integer: %d\nLength:%d\n\n",a,b);
    v2();
}

lenght(int n)
{
    int l=1;
    while(n>9){ l++; n/=10; }
  return l;

}


And also be noted that the operation function is v2 here. :)

Hope it will help you.

Related Posts
Previous
« Prev Post