How many zeroes are there after the last non-zero digit of a million? a trillion? To easily identify that, let us make a program to count and print the number of zeroes after the last non-zero digit of a number. For example, in 20400, there are 2 zeroes after the last non-zero digit of the number, 4. Are you up for this challenge?
#include <iostream>
using namespace std;
int countZeros(int n, int count = 0){
if(n % 10){
return count;
}
return countZeros(n / 10, ++count);
}
int main(){
cout<<countZeros(2040000);
return 0;
}
Comments
Leave a comment