使用递归反转整数的数字 [英] Reversing digits of an integer using recursion

查看:377
本文介绍了使用递归反转整数的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用C语言编写。我想使用递归来反转输入整数,所以如果输入是456,则输出应该是654.它只需要使用正数。

我'我已经编写了这个函数,但我得到的唯一输出是0。我知道它与sum = 0相同0;因为当我将''sum''改为开头的任何其他数字时,输出该数字。几乎就像'if''条款被完全跳过一样。

这是代码:

I am writing in C. I want to reverse the input integer using recursion so if the input is 456, the output should be 654. it only needs to work with positive numbers.
I''ve already written this function but the only output i get for any input is ''0''. I know that its the same 0 from sum=0; because when i change ''sum'' to any other number at the beginning, that number is outputted. its almost as if the ''if'' clause is being skipped completely.
Here is the code:

展开 | 选择 | Wrap | 行号

推荐答案

<已删除代码请阅读如何回答问题>
<Code Removed Please Read how to respond to a question>


ab12,你有一个递归函数,但你从不使用该递归的返回值。


if语句永远不返回值的真正块。

函数实际返回的唯一值是if语句的false块中的0。
ab12, you have a recursive function yet you never use the return value of that recursion.

The true block of you if statement never returns a value.

The only value actually returned by your function is 0 in the false block of the if statement.



ab12,你有一个递归函数但你从不使用该递归的返回值。


如果语句永远不会返回值,那么你的真正块。


函数实际返回的唯一值是if语句的false块中的0。
ab12, you have a recursive function yet you never use the return value of that recursion.

The true block of you if statement never returns a value.

The only value actually returned by your function is 0 in the false block of the if statement.



这是重点,因为最终我希望函数返回任何sum的值是......所以因为那不起作用我能做些什么来解决这个问题?

That was kind of the point because eventually i want the function to return whatever the value of sum is...so since thats not working what could i do to fix this problem?


这篇关于使用递归反转整数的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆