0
write a program to input a number and print the number of digits used.
without array
3 Respostas
+ 2
std::ceil(std::log10(std::abs(x))); does the charm, too. :-)
Nevertheless, you have to include <cmath>.
+ 1
#include <iostream>
void main()
{
int x, n(0);
std::cin >> x;
while (x != 0)
{
x /= 10;
++n;
}
std::cout << n;
}
Not tested it but I believe this will work for any positive integer.
+ 1
thanks man it works