Finding the number of digits of an integer

前端 未结 17 2197
难免孤独
难免孤独 2020-12-07 16:32

What is the best method to find the number of digits of a positive integer?

I have found this 3 basic methods:

  • conversion to string

             
    
    
            
17条回答
  •  一个人的身影
    2020-12-07 16:56

    Keep it simple:

    long long int a = 223452355415634664;
    
    int x;
    for (x = 1; a >= 10; x++)
    {
       a = a / 10;
    }
    
    printf("%d", x);
    

提交回复
热议问题