recursive function digits of a positive decimal integer in reverse order c++

前端 未结 5 501
清歌不尽
清歌不尽 2021-01-21 18:22

I have an assignment to write a recursive function that writes the digits of a positive integer in reverse order. My problem is that the function doesn\'t display the reverse co

5条回答
  •  醉梦人生
    2021-01-21 18:35

    You could also do:

    int reverse(int number,int n) {
    if(number > n) {
        cout << number << endl;
        reverse(number-1,n);
    }
    

    But you should get rid of first number printing twice.

提交回复
热议问题