answersLogoWhite

0

You don't actually have to use a stack, but if your teacher wants that, you can please them:

int fact (int n)

{

int i, fct;

whatever_stack_type_you_have s;

initialize_your_stack (s);

push (s, n);

for (i=1, fct=1; i<n; ++i) fct *= i;

pop (s, &n);

fct *= n;

destroy_your_stack (s);

return fct;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

How to write a program to find the delimiter matching in stacks?

== == using recursions: unsigned int Factorial( unsigned int x) { if(x&gt;0) { return ( x * Factorial(x-1)); } else { return(1); } } factorial: unsigned int Factorial( unsigned int x) { unsigned int u32fact = 1; if( x == 0) { return(1); } else { while(x&gt;0) { u32fact = u32fact *x; x--; } } }


By using call by reference find the factorial of a number?

chutia mc,bc bhosdika


Write the Pseudocode to find the factorial of a number?

Pseudo code+factorial


Algorithm to find factorial using functions?

factorial using recursion style in c++ is unsigned int fact(unsigned int a) { if (a&lt;=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&lt;=n;i++) f*=i ; return f; }


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


How you can find a factorial of a number without using multiple operator?

If you really wanted to do this, you could simulate multiplication with repeated addition.


Can you make 4 stacks of pennies using 9 pennies?

Yes. However, they will not be regular stacks.


A program for simple factorial in prolog?

In Prolog, a simple factorial program can be defined using recursion. Here's a basic implementation: factorial(0, 1). % Base case: factorial of 0 is 1 factorial(N, Result) :- N &gt; 0, N1 is N - 1, factorial(N1, Result1), Result is N * Result1. % Recursive case You can query the factorial of a number by calling factorial(N, Result). where N is the number you want to compute the factorial for.


Flowchart to find factorial of a given no?

Kat


Jntu 2-2 oops through java answers?

write a java program to find factorial using recursive and non recursive


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


How do you get 53 using only 4 fours?

4 factorial plus 4 factorial plus the square root of 4 divided by .4