Answer to Question #310894 in C++ for Secret Agent

Question #310894

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?


Input

A line containing an integer.

20400

Output

A line containing an integer.

2




1
Expert's answer
2022-03-15T12:12:32-0400

Here is program:

int main()
{


    double a;
    cout << "a="; cin >> a;
    string s = to_string(a);


    if (s[s.size() - 1] == '0')
        for (size_t i = s.size() - 1; s[i] == '0'; i--)
            s.erase(i, 1);


    if (s[s.size() - 1] == '.')
        s.erase(s.size() - 1, 1);


    cout << "s=" << s << endl;
}

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