reverse the position of integer digits?

后端 未结 13 2515
予麋鹿
予麋鹿 2021-02-09 15:00

i have to reverse the position of integer like this

input = 12345

output = 54321

i made this but it gives wrong output e.g 5432

#include         


        
13条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-09 15:24

    int _tmain(int argc, _TCHAR* argv[])
    {
    int x = 1234;
    int out = 0;
    while (x != 0)
    {
        int Res = x % (10 );
        x /= 10;
        out *= 10;
        out +=  Res;
    }
    cout << out;
    
    
    } 
    

提交回复
热议问题