Last active
February 3, 2016 08:33
-
-
Save salayhin/3fbe1eabb1fb0531c387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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