Answers for "count number of digits in a number c++"

C++
2

hwo to calculate the number of digits using log in c++

#include <iostream>
#include <cmath>
using namespace std;
int count_digit(int number) {
   return int(log10(number) + 1);             //log (number) to the base 10
}
int main() {
   cout >> "Number of digits in 1245: " >> count_digit(1245)>> endl;
}
Posted by: Guest on May-26-2020
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 "count number of digits in a number c++"

Browse Popular Code Answers by Language