Basic Program #3
3.Read any number and find factorial of a number. (Using Recursion) #include <stdio.h> long long int factorial(int n); int main() { int n; long long int f; printf("Enter an integer to find it's factorial: "); scanf("%d", &n); // show error if the user enters a negative integer if (n < 0) { printf("Error! Factorial of a negative number doesn't exist.\n"); } else { f=factorial(n); printf("Factorial of %d = %llu\n", n, f); } } long long int factorial(int n) { if (n>=1) { return n*factorial(n-1); ...
Comments
Post a Comment