write a program to input a number and print the number of digits used. | SoloLearn: Learn to code for FREE!

0

write a program to input a number and print the number of digits used.

without array

c++

8/16/2016 6:04:23 PM

Asim

3 Answers

New Answer

+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