answersLogoWhite

0

// returns n!

int fact(int n) {

int f_n = 1;

for(int i = n; i > 1; --i) {

f_n *= n;

}

return f_n;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Continue Learning about Engineering

What is a factorial function in Visual Basic?

' Iterative solution Function iterativeFactorial(ByVal n As Long) As Long Dim factorial As Long = 1 For i As Long = 1 To n factorial *= i Next Return factorial End Function ' Recursive solution Function recursiveFactorial(ByVal n As Long) As Long If n <= 1 Then Return n End If Return n * recursiveFactorial(n - 1) End Function


What is algorithm evaluation?

evaluation iz same as the testing of an algorithm. it mainly refers to the finding of errors by processing an algorithm..


Difference between deterministic and nondeterministic algorithm in design and analysis of algorithm?

Algorithm is deterministic if for a given input the output generated is same for a function. A mathematical function is deterministic. Hence the state is known at every step of the algorithm.Algorithm is non deterministic if there are more than one path the algorithm can take. Due to this, one cannot determine the next state of the machine running the algorithm. Example would be a random function.FYI,Non deterministic machines that can't solve problems in polynomial time are NP. Hence finding a solution to an NP problem is hard but verifying it can be done in polynomial time. Hope this helps.Pl correct me if I am wrong here.Thank you.Sharada


How do you use prim's algorithm to find a spanning tree of a connected graph with no weight on its edges?

Prims Algorithm is used when the given graph is dense , whereas Kruskals is used when the given is sparse,we consider this because of their time complexities even though both of them perform the same function of finding minimum spanning tree. ismailahmed syed


What is simulation recursion in C?

The factorial f(n) = n * (n-1) * (n-2) * .. 1. For example factorial 5 (written as 5!) = 5 x 4 x 3 x 2 x 1 = 120. The function below returns the factorial of the parameter n. int factorial( int n) { if (n==1) return 1 else return n* factorial( n-1) ; }

Related Questions

What is a factorial function in Visual Basic?

' Iterative solution Function iterativeFactorial(ByVal n As Long) As Long Dim factorial As Long = 1 For i As Long = 1 To n factorial *= i Next Return factorial End Function ' Recursive solution Function recursiveFactorial(ByVal n As Long) As Long If n <= 1 Then Return n End If Return n * recursiveFactorial(n - 1) End Function


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

no answer....pls post


What is the fastest algorithm for finding the shortest path in a graph?

The fastest algorithm for finding the shortest path in a graph is Dijkstra's algorithm.


What is algorithm evaluation?

evaluation iz same as the testing of an algorithm. it mainly refers to the finding of errors by processing an algorithm..


Design an algorithm for finding all the factors of positive integerfor example in the case of the integer 12your algorithm should report 12346 and 12?

design an algorithm for finding all the factors of a positive integer


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

kjhk


What is the fastest shortest path algorithm for finding the most efficient route between two points?

The fastest shortest path algorithm for finding the most efficient route between two points is Dijkstra's algorithm.


What has a value of the first term and the rule for finding each term based on the term before?

Any iterative sequence.


Numerical method for solving can eqution bisection method?

A root-finding algorithm is a numerical method, or algorithm, for finding a value. Finding a root of f(x) − g(x) = 0 is the same as solving the equation f(x) = g(x).


What does Newton's law of Raphson state?

Newton's method, also known as Newton-Raphson method, is an iterative technique for finding the roots of a real-valued function. It starts with an initial guess and refines the estimate in each iteration by using the derivative of the function. The method is based on the principle that a function can be approximated locally by a linear function at a root.


What is the average running time of Dijkstra's algorithm for finding the shortest path in a graph?

The average running time of Dijkstra's algorithm for finding the shortest path in a graph is O(V2), where V is the number of vertices in the graph.


What are the differences between the A algorithm and Dijkstra's algorithm in terms of their efficiency and optimality in finding the shortest path?

The A algorithm is more efficient than Dijkstra's algorithm because it uses heuristics to guide its search, making it faster in finding the shortest path. A is also optimal when using an admissible heuristic, meaning it will always find the shortest path. Dijkstra's algorithm, on the other hand, explores all possible paths equally and is not as efficient or optimal as A.