Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int factorial(int n){
- if(n <= 1){
- return 1;
- }
- else{
- n = n * factorial(n - 1);
- return n;
- }
- }
- int main(void){
- int n, f;
- printf("Factorial(N)\n");
- while(1){
- printf("\nN = ");
- scanf("%d", &n);
- if(n >= 0){
- f = factorial(n);
- printf("Factorial(%d) = %d\n", n, f);
- }
- else{
- printf("factorial is not defined for negative numbers");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment