Number of Digits

 

#include <bits/stdc++.h>
using namespace std ;

int count (int n){
//Base case
if (n==0) return 0;
//Recursive case
int smallAns = count(n/10);
//Calculation
return smallAns + 1 ;

}

int main(){
int n ;
cin >> n;
cout << count(n) << '\n';

}

Comments

Popular posts from this blog

CodeChef::CSUB

How Recursion Works?

CodeChef::TREE2