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
/** | |
* 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; | |
} |
No comments:
Post a Comment