Answers for "how to find how many digits a number has in c++"

4

how to find how many digits a number has in c++

#include <iostream>
#include <cmath>

unsigned int getNumberOfDigits (int i)
{
    return i > 0 ? log10((double) i) + 1 : 1;
}

int main()
{
	std::cout << "Number of digits: " << getNumberOfDigits(/*Example*/6738) << std::endl;  
	return 0;
}
Posted by: Guest on October-24-2020

Code answers related to "how to find how many digits a number has in c++"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language