How to get the digits of a number without converting it to a string/ char array?

前端 未结 15 1332
既然无缘
既然无缘 2020-11-27 04:07

How do I get what the digits of a number are in C++ without converting it to strings or character arrays?

15条回答
  •  甜味超标
    2020-11-27 04:51

    A simple solution would be to use the log 10 of a number. It returns the total digits of the number - 1. It could be fixed by using converting the number to an int.

    int(log10(number)) + 1
    

提交回复
热议问题