Answer to Question #271463 in C++ for Nokachi

Question #271463

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?


1
Expert's answer
2021-11-26T07:08:39-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS