C program to find the factorial of a given number using recursion
kw.c
#include<stdio.h>longfacto(longx);intmain(){longn,a;printf("———————————————————————————————————————————");printf("\nProgram to find the factorial of a given number");printf("\n———————————————————————————————————————————");printf("\nEnter the number ");scanf("%ld",&n);if(n<0){printf("Please enter a positive number or zero");}elseif(n>=26){printf("Please enter a number less than 26");}else{a=facto(n);printf("\nThe factorial of %ld is %ld",n,a);}printf("\n———————————————————————————————————————————\n");return0;}longfacto(longn){if(n>=1){returnn*facto(n-1);}else{return1;}}
Output
kodingwindow@kw:~$ gcc kw.c kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to find the factorial of a given number
———————————————————————————————————————————
Enter the number 0
The factorial of 0 is 1
———————————————————————————————————————————
kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to find the factorial of a given number
———————————————————————————————————————————
Enter the number 25
The factorial of 25 is 7034535277573963776
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.