reverse the position of integer digits?

后端 未结 13 2516
予麋鹿
予麋鹿 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:32

    Your loop terminates too early. Change

    }while(num/i!=0);
    

    to

    }while((num*10)/i!=0);
    

    to get one more iteration, and your code will work.

提交回复
热议问题