Thursday, 19 December 2019

Count number of digits using recursion in C

#include<stdio.h>
#include<conio.h>
int count(int);
int main()
{
int n,s;
printf("Enter the number: ");
scanf("%d",&n);
s=count(n);
printf("The number of digits present is %d",s);
return 0;
}
int count(int n)
{
 if(n<10)
 return 1;
 else
 return (1+count(n/10));
}

No comments:

Post a Comment

Convey your thoughts to authors.