Identify the digits in a given number.

前端 未结 7 718
滥情空心
滥情空心 2020-12-07 03:41

I\'m new to programming, and I\'m stuck at a problem. I want my program to identify the separate digits in a given number, like if I input 4692, it should ident

7条回答
  •  既然无缘
    2020-12-07 04:22

    Simple and nice

    void PrintDigits(const long n)
    {
        int m = -1;
        int i = 1;
    
        while(true)
        {
            m = (n%(10*i))/i;
            i*= 10;
            cout << m << endl;
    
            if (0 == n/i)
                break;
        }
    }
    

提交回复
热议问题