Answers for "count digits of a number using recursion in c"

0

count digits of a number using recursion in c

/*C program to count digits using recursion.*/
 
#include <stdio.h>
 
//function to count digits
int countDigits(int num)
{
    static int count=0;
     
    if(num>0)
    {
        count++;
        countDigits(num/10);
    }
    else
    {
        return count;
    }
}
int main()
{
    int number;
    int count=0;
     
    printf("Enter a positive integer number: ");
    scanf("%d",&number);
     
    count=countDigits(number);
     
    printf("Total digits in number %d is: %d\n",number,count);
     
    return 0;
}
Posted by: Guest on July-14-2021

Code answers related to "count digits of a number using recursion in c"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language