C++ - how to find the length of an integer

后端 未结 13 1399
你的背包
你的背包 2020-12-09 10:03

I\'m trying to find a way to find the length of an integer (number of digits) and then place it in an integer array. The assignment also calls for doing this without the use

13条回答
  •  再見小時候
    2020-12-09 10:23

    Code for finding Length of int and decimal number:

    #include
        #include
        using namespace std;
        int main()
        {
            int len,num;
            cin >> num;
            len = log10(num) + 1;
            cout << len << endl;
            return 0;
        }
        //sample input output
        /*45566
        5
    
        Process returned 0 (0x0)   execution time : 3.292 s
        Press any key to continue.
        */
    

提交回复
热议问题