answersLogoWhite

0


Best Answer

unsigned long nfact(int n) if (n==2) return n else return n*nfact(n-1);

For 32-bit integers, this program will fail at N==13, due to overflow. For 64-bit integers, it will fail at N==21. A solution for this is an arbitrary decimal arithmetic library, perhaps based on linked lists.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a c program to calculate factorial using recursion?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Program for calculating factorial no using recursion in c?

factorial n is given by formula n! = n.(n-1)....1 int i; long x; x =1; for (i=n;i>1;i--) x = x*i ; will calculate factorial. I have put x as long to avoid integer overflow. checks for n is positive etc. to be added.


What is a Flow chart for finding factorial of a given number using recursion function?

no answer....pls post


What is the C program for heap sort using recursion?

123


Program to find factorial of a number using inheritance?

/*71.PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION*/ #include<stdio.h> #include<conio.h> int fact(int); void main() { int n,f; clrscr(); printf("Enter number whose factorial is to be calculated: "); scanf("%d",&n); if(n>0) { f=fact(n); printf("factorial of %d is %d",n,f); } else printf("Factorial of numbers less than 1 does not exist"); getch(); } int fact(int n) { int facto=1; if(n>1) facto=n*fact(n-1); else return 1; return(facto); }


Program to find the factorial of a number using recursion?

/*program to find the factorial of a given number*/ #include<stdio.h> #include<conio.h> int fact(int); void main() { int n,c; printf("\n enter the number for which you want to find the factorial"); scanf("%d",&n); c=fact(n); printf("\n the factorial of the number %d is %d",n,fact); getch(); } int fact(int n) { int k; if(n==0) return(1); else k=n*fact(n-1); return(k); }


Algorithm to find factorial using functions?

factorial using recursion style in c++ is unsigned int fact(unsigned int a) { if (a<=1) return 1; else { f*=fact(a-1); return a; } } when using looping structure factorial is unsigned int fact (unsigned int n) { unsigned int i,f=1; for(i=1;i<=n;i++) f*=i ; return f; }


Program for finding the factorial of the two given number using constructor?

kjhk


Write a program using recursion which should take two values and display 1st value raised to the power of second value?

Write a program using recursion which should take two values and display 1st value raised to the power of second value.


What is recursion in programing?

A recursive method (or function) is one that calls itself. Here is a popular example: The factorial function n! (read the exclamation mark as: factorial of n, or n factorial), for a positive integer, is the product of all numbers up to that number. For example, 4! = 1 x 2 x 3 x 4. In math, the factorial is sometimes defined as: 0! = 1 n! = n x (n-1)! (for n > 0) You can write a function or method, using this definition. Here is the pseudocode: function factorial(n) if (n = 0) return 1 else return n * factorial(n - 1) Note that this is not very efficient, but there are many problems that are extremely complicated without recursion, but which can be solved elegantly with recursion (for example, doing something with all files in a folder, including all subfolders).


What is the algorithm n flowchart for calculating factorial of number using recursion?

A flowchart for factorial of number can be made using different software's. Microsoft Word is the most popular software for beginners to make simple flowcharts.In order to draw the flowchart write the number at the top of the paper and then draw two lines under it going slightly to the sides. Decide what two numbers can be multiplied to equal that number. Keep going until you can no longer get to smaller numbers.


Program in c to generate table of factorials?

#include #include using std::cin;using std::cout;using std::endl;using std::tolower;long factorial(int N);int main(){int N = 0; //factorial of Nchar command = 'n';do{cout > N;cout


Program to find n th fabonacci number?

#include #include using std::cin;using std::cout;using std::endl;using std::tolower;long factorial(const int& N);int main(){int N = 0; //factorial of Nchar command = 'n';do{cout > N;cout