Write a c program in recursive function for factorial
Answers
Answered by
0
To understand this example, you should have the knowledge of followingC programming topics:
★C Programming Functions
★C Programming User-defined functions
★C Programming Recursion
The factorial of a positive number n is given by:
factorial of n (n!) = 1*2*3*4....n
The factorial of a negative number doesn't exist. And the factorial of 0 is 1.
You will learn to find the factorial of a number using recursion in this example. Visit this page to learn, how you can find the factorial of a number using loop.
Example: Factorial of a Number Using Recursion
(better to refer pic you can understand clearly)
#include <stdio.h> long int multiplyNumbers(int n); int main() { int n; printf("Enter a positive integer: "); scanf("%d", &n); printf("Factorial of %d = %ld", n, multiplyNumbers(n)); return 0; } long int multiplyNumbers(int n) { if (n >= 1) return n*multiplyNumbers(n-1); else return 1; }
Output
Enter a positive integer: 6 Factorial of 6 = 720
★C Programming Functions
★C Programming User-defined functions
★C Programming Recursion
The factorial of a positive number n is given by:
factorial of n (n!) = 1*2*3*4....n
The factorial of a negative number doesn't exist. And the factorial of 0 is 1.
You will learn to find the factorial of a number using recursion in this example. Visit this page to learn, how you can find the factorial of a number using loop.
Example: Factorial of a Number Using Recursion
(better to refer pic you can understand clearly)
#include <stdio.h> long int multiplyNumbers(int n); int main() { int n; printf("Enter a positive integer: "); scanf("%d", &n); printf("Factorial of %d = %ld", n, multiplyNumbers(n)); return 0; } long int multiplyNumbers(int n) { if (n >= 1) return n*multiplyNumbers(n-1); else return 1; }
Output
Enter a positive integer: 6 Factorial of 6 = 720
Attachments:
Similar questions
Social Sciences,
7 months ago
Science,
7 months ago
Science,
7 months ago
Math,
1 year ago
English,
1 year ago