调试器显示分段错误。无法定位故障
#include <stdio.h>
void fun(int x)
{
if(x<=20)
{
printf("d\n",x);
return fun(2*x);
return fun(x/2);
}
}
main()
{
int x;
printf("Enter the number\n");
scanf("%d",x);
fun(x);
}
#include <stdio.h>
void fun(int x)
{
if(x<=20)
{
printf("d\n",x);
return fun(2*x);
return fun(x/2);
}
}
main()
{
int x;
printf("Enter the number\n");
scanf("%d",x);
fun(x);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
应该是
scanf("%d", &x);
,也可能是printf("%d\n", x);
。此外,您还从
void
函数返回一些内容(两次!)。您的代码将无法按原样运行。That should be
scanf("%d", &x);
, and probablyprintf("%d\n", x);
.Also, you're returning something (twice!) from a
void
function. Your code will not work as it is.在函数中,如果您打算打印 x 的值,则应该是 printf("%d\n",x);
你缺少 % 符号。函数中的第二个 return 语句也永远不会被执行。
in the function if you are planning to print the value of x it should be printf("%d\n",x);
you are missing % symbol.also the second return statement in your function will never be executed..
除了其他人所说的之外,在修复所有其他编程错误之后,您正在将程序引导至无限递归。
On top of what other folks said, after you fix all other programmatic mistakes you are directing your program to an infinite recursion.
这是我一直在寻找的正确程序。谢谢大家!
This is the correct program, I was looking for. Thank u all!