I am trying to find the number of digits in the input integer.
But it always prints "no. of digits: 1".
In place of getting integer i
from function, if I use "static int i = 0;
" inside the function it works perfectly.
And I can't understand this behavior.
#include <stdio.h>
int func(int a, int i)
{
if (a != 0)
{
i++;
func(a / 10, i);
}
return i;
}
int main()
{
int a, c;
printf("Enter the No:");
scanf("%d", &a);
c = func(a, 0);
printf("No. of digits: %d", c);
return 0;
}