« Print the number of digits present in a number recursively.
Problem
Print the number of digits present in a number recursively.
Input Format :
Integer n
Output Format :
Count of digits
Constraints :
1 <= n <= 10^6
Sample Input 1 :
156
Sample Output 1 :
3
Sample Input 2 :
7
Sample Output 2 :
1
Solution
1#include<iostream>2#include "Solution.h"3using namespace std;45int count(int n){6 if(n == 0){7 return 0;8 }9 int smallAns = count(n / 10);10 return smallAns + 1;11}1213int main(){14 int n;15 cin >> n;1617 cout << count(n) << endl;18}