Develop a C program to find the factorial of a given integer number using recursion
Code
#include<stdio.h>long factorial(int n){if (n == 0)return 1;elsereturn(n * factorial(n-1));}void main(){int number;long fact;printf("Enter a number: ");scanf("%d", &number);fact = factorial(number);printf("Factorial of %d is %ld\n", number, fact);return 0;}
Output
2 Comments
using function
ReplyDeleteint fac(int n)
{
if (n == 0)
return 1;
else
return(n * fac(n-1));
yep my bad, updated!
DeletePost a Comment