Functions That Call Themselves: Recursion for factorials - C Function

C examples for Function:Recursive Function

Description

Functions That Call Themselves: Recursion for factorials

Demo Code

#include <stdio.h>

unsigned long long factorial(unsigned long long);

int main(void){
 unsigned long long number = 0LL;
  printf("Enter an integer value: ");
  scanf("%llu", &number);
  printf("The factorial of %llu is %llu\n", number, factorial(number));
  return 0;//from  w w  w.  j  a v a 2  s. co  m
}

// A recursive factorial function
unsigned long long factorial(unsigned long long n){
  if(n < 2LL)
    return n;

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

Related Tutorials