Advertisements

Search results for factorial

Example:[1]

            Write C function to calculate the factorial of a number and illustrate the use of recursion. 
          

            #include <stdio.h>
#include <stdlib.h>
int fact(int );
int main() {
  int num = 5;
  int res;
  res = fact(num);
  printf("Factorial is %d\n",res);
  return 0;
}
int fact(int x)
{
  if(x > 1)
  {
    return x * fact(x-1);
  }else
  {
    return 1;
  }
}

          

 Search Links


 Popular C search MCQs


 Popular C search examples