ShankarYoda / CppAlgorithms

Hactoberfest-2022
8 stars 39 forks source link

Create Calculating the most significant digit in cpp.cpp #6

Closed jaydipoo7 closed 2 years ago

jaydipoo7 commented 2 years ago

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