To calculate the most significant digit of any number log can be directly used to calculate it. We can calculate the number of digits and then divide the number by 10^(number of digits-1)
Suppose the number is N then
Let int K = log10(N); // number of digits in a number=log10(N)+1 And int X = pow(10, K);
Then int ans=N/X will be the most significant digit
To calculate the most significant digit of any number log can be directly used to calculate it. We can calculate the number of digits and then divide the number by 10^(number of digits-1)
Suppose the number is N then Let int K = log10(N); // number of digits in a number=log10(N)+1 And int X = pow(10, K); Then int ans=N/X will be the most significant digit