Skip to content

Instantly share code, notes, and snippets.

@salayhin
Last active February 3, 2016 08:33
Show Gist options
  • Save salayhin/3fbe1eabb1fb0531c387 to your computer and use it in GitHub Desktop.
Save salayhin/3fbe1eabb1fb0531c387 to your computer and use it in GitHub Desktop.
/**
This program will calculate factorial value of a given input. Reccursive function is used in this program.
**/
#include<stdio.h>
/* Main function */
int main(){
int n;
int result = 0;
printf("Enter Int value for calculating factorial: ");
scanf("%d", &n);
result = factorial(n);
printf("Factorial %d = %d", n, result);
printf("\n");
return 0;
}
/* Function for calculating factorial */
int factorial(int n){
printf("Calculating %d", n);
printf("\n");
if(n == 1){
return 1;
}
int f = n * factorial(n-1);
printf("Done Calculating %d", f);
printf("\n");
return f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment