Using recursion to sum numbers

后端 未结 16 2078
轮回少年
轮回少年 2021-02-05 15:45

I have just been studying the concept of recursion and I thought that I would try a simple example. In the following code, I am attempting to take the numbers: 1, 2, 3, 4, 5, an

16条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-05 16:12

    You're returning 1 in the else clause. You should be returning 0:

    else
    {
        return 0;
    }
    

    If the value is not greater than zero, why would you return one in the first place?

提交回复
热议问题