Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Factorial Program in C Using Recursion
#1
Advertisment
Hi friend today I am going to share Factorial Program in C. Here is the code for Factorial Program in C Using Recursion. I have shared the source link as well for more details.

Factorial Program in C

Code:
#include<stdio.h>

long factorial(int);

int main(){
  int n;
  long f;
  printf("Please Enter a number\n");
  scanf("%d", &n);
  if (n < 0){
    printf("Negative numbers have no factorial.\n");
  }else{
    f = factorial(n);
    printf("%d! = %ld\n", n, f);
  }
  return 0;
}

long factorial(int n){
  if (n == 0){
    return 1;
  }else{
    return(n * factorial(n-1));
  }
}

Source: http://howtocode.pk/factorial-program-in-c/
Advertisment
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Prime Number Program in PHP w3schools Kelly 2 2,921 10-05-2018, 05:44 PM
Last Post: kim kardashian

Forum Jump:


Users browsing this thread: 1 Guest(s)