Created
May 13, 2011 11:02
-
-
Save mbalayil/970350 to your computer and use it in GitHub Desktop.
To find the factorial of a number in C
This file contains hidden or 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
/** | |
* To find the factorial of a number | |
**/ | |
#include<stdio.h> | |
#include<stdlib.h> | |
int main(void) | |
{ | |
int n, i, f; | |
printf("Enter any number:"); | |
scanf("%d", &n); | |
if(n < 0) { | |
printf("\nFactorial does not exist for negative numbers\n"); | |
exit(0); | |
} | |
for(f = 1, i = n; i > 0; i--) | |
f = f * i; | |
printf("\nFactorial of %d is %d\n", n, f); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment