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
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;
}
Comments
Leave a comment