0
我是新来的C编程语言,我正在尝试学习计算给定数字的阶乘的递归。我的问题是调试printf
陈述正在打印2,6,24,120
,如果我输入'5'。如果将函数调用替换为相应的值并一次计算阶乘,它如何打印4次?调试阶乘递归
#include<stdio.h>
#include<stdlib.h>
int factorial(int n);
int main()
{
int num;
int fact_val;
printf("Enter the number for which you are going to compute the factorial:");
scanf("%d",&num);
fact_val=factorial(num);
printf("The factorial of the given number is %d\n",fact_val);
return 0;
}
int factorial(int n)
{
int factorial_val;
if(n==1)
return 1;
else
{
factorial_val=factorial(n-1)*n;
printf("Debugger-%d\n",factorial_val);
}
return factorial_val;
}
了解如何使用环境的调试工具,然后通过你的代码的一步。您将学到的远不止是使用debug printf语句。 – 2012-08-14 01:14:36