Computer Science, asked by malaikabatool03, 4 months ago

Write a program to find factorial of a number.

Answers

Answered by Anonymous
1

\huge\bold\purple{Factorial \: program \: in C\: using \: recursion}

#include<stdio.h>

long factorial(int);

int main()

{

int n;

long f;

printf("Enter an integer to find its factorial\n");

scanf("%d", &n);

if (n < 0)

printf("Factorial of negative integers isn't defined.\n");

else

{

f = factorial(n);

printf("%d! = %ld\n", n, f);

}

return 0;

}

long factorial(int n)

{

if (n == 0) // Base case

return 1;

else

return (n*factorial(n-1));

}

\huge\bold\purple{BTS \: EXO}

Similar questions