Skip to content

Commit

Permalink
Create function_factorial.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrigank005 authored Oct 25, 2024
1 parent e2417e3 commit 49d8638
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mriganksingh/function_factorial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
int factorial(int n)
{
if (n == 0 || n == 1)
{
return 1;
}
else
{
return n * factorial(n - 1);
}
}
int main()
{
int num;
printf("Enter a number to find its factorial: ");
scanf("%d", &num);
if (num < 0)
{
printf("Factorial is not defined for negative numbers.\n");
}
else
{
printf("Factorial of %d is %d\n", num, factorial(num));
}
return 0;
}

0 comments on commit 49d8638

Please sign in to comment.