Pages

Factorial Number using Recursive Function in C

This program calculate the factorial of given number.

factorial.c
include <stdio.h>
include<conio.h>

int fact(int n)
{
   if(n == 0 | n == 1)
      return 1;

  else
     return(n * fact(n - 1));
}

void main()
{
   int n, result;
   printf("Enter Number : ");
   scanf("%d", &n);
   result = fact(n);
   printf("\n The factorial of %d is %d", n, result);
   getch();
}

Output:
Enter Number : 5
The Factorial of 5 is 120

@msucil

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment