Given an integer N, count and return the number of zeros that are present in the given integer using recursion.

Count Zeros

PROBLEM:-Given an integer N, count and return the number of zeros that are present in the given integer using recursion.

Input Format :
Integer N
Output Format :
Number of zeros in N
Constraints :
0 <= N <= 10^9
Sample Input 1 :
10204
Sample Output 1 :
2
Sample Input 2 :
708000
Sample Output 2 :
4

SOLUTION:-

#include <iostream>
using namespace std;


int countZeros(int n) 
{
    // Write your code here
   
   if(n==0)
   return 0;
    else{
   int d=n%10;
   if(d==0)
   {
       return countZeros(n/10)+1;
   }
   else{
       countZeros(n/10);
   }
    }
       
        
}



int main() {
    int n;
    cin >> n;
    cout << countZeros(n) << endl;
}

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *