Count Zeros

 

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

int countZeros(int n){
    //base case
    if(n==0return 0;

    //recursive case
    int smallAns = countZeros(n/10) ;

    //calculation
    int last_digit = n%10 ;
    if(last_digit == 0return 1+smallAns ;
    else
    {
        return smallAns ;
    }
    

}


int main() {
    cout << countZeros(10320) ;

    return 0 ; 
}

Comments

Popular posts from this blog

CodeChef::CSUB

How Recursion Works?

CodeChef::TREE2