digits count usint recursion in c program

C Program find digits count using function and recursion  : 


In this C program, we are going to learn how to count total number of digits of a number using recursion?
Given an integer number and we have to count the digits using recursion using C program.
In this program, we are reading an integer number and counting the total digits, here countDigits()is a recursion function which is taking number as an argument and returning the count after recursion process.

Example : 
 Input          number  :   12134
 Output      Total number  : 5


C program to count digits in c recursion porgram code : 



#include<stdio.h>

int digitecount(int num)
{
    static int count=0;
    if(num!=0)
    {
        count ++;
        digitecount(num/10);
    }
    else
        return count;
}
int main()
{
    int n,bb;
    printf("Ente the number ");
    scanf("%d",&n);
    bb=digitecount(n);
    printf("Total digits in number = %d",bb);

    return 0;
}



Output  : 



No comments

Powered by Blogger.