0
What is wrong in my factorial code
3 Answers
+ 5
#include <stdio.h>
int fact(int n);
int main() {
int n;
printf("enter a number");
scanf("%d",&n);
printf("result: %d",fact(n));
}
int fact(int n)
{
int result;
if(n==0)
result=1;
else
result=n*fact(n-1);
return result;
}
+ 1
#include <stdio.h>
int fact(int n);
int main() {
int n;
printf("enter a number\n");
scanf("%d", &n);
n = fact(n);
printf("result %d", n);
return 0;
}
int fact(int n) {
return n <= 1 ? 1 : n*fact(n-1);
}
0
Thanks for helping