0

What is wrong in my factorial code

https://code.sololearn.com/cqGvMZTKGYSG/?ref=app

1st May 2020, 5:01 AM
Aman Prasad
Aman Prasad - avatar
3 ответов
+ 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; }
1st May 2020, 5:06 AM
Cmurio
Cmurio - avatar
+ 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); }
1st May 2020, 5:22 AM
ChaoticDawg
ChaoticDawg - avatar
0
Thanks for helping
1st May 2020, 1:36 PM
Aman Prasad
Aman Prasad - avatar