Search This Blog

Loading...

Write a program to Count the digits of a given number without using Loop .

#include<stdio.h>
#include<conio.h>

int countDigits(num);

int main()
{

    int num,count;

    printf("Enter a number: ");
    scanf("%d",&num);

    count = countDigits(num);

    printf("Total digits is:  %d",count);
    getch();
}

int countDigits(int num)
{
    static int count=0;

    if(num!=0)
    {
        count++;
        countDigits(num/10);
    }

    return count;
}

No comments:

Post a Comment