我希望代码是自我解释的。
#include <iostream>
#include <cmath>
using namespace std;
int digits(int inp); //Prototyping correct?
int main()
{
cout << digits(10);//I intend to have a cin statement here
//Set to a constant for checking, getting 24683872. Expected 2.
}
int digits(int inp)
{
float a = 10;
int i = 1;
int n;
int m_d = 1 ;
while (m_d >= 1) //Keeps dividing by higher powers of 10 to find digits.
{
n = int(pow(a, i));
m_d = inp / n;
i++;
}
cout << (i-1);
}