answersLogoWhite

0

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;

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

what is the flow chart and algorithm to find the factorial of a given number?

A flowchart to find the factorial of a given number typically includes the following steps: Start, read the input number, check if the number is less than 0 (return an error for negative numbers), initialize a result variable to 1, and then use a loop to multiply the result by each integer from 1 to the input number. The algorithm can be summarized as follows: if ( n ) is the input number, initialize ( \text{factorial} = 1 ); for ( i ) from 1 to ( n ), update ( \text{factorial} = \text{factorial} \times i ); finally, output the factorial.


Using the Euclid's algorithm find the multiplicative inverse of 1234 mod4321?

Using the extended Euclidean algorithm, find the multiplicative inverse of a) 1234 mod 4321


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

chutia mc,bc bhosdika


How do you find common dinomanater in fractions?

Using the Euclidean algorithm


How can you find factorial of each element in array using pointer?

To find the factorial of each element in an array using pointers in C, you can create a function that takes a pointer to the array and its size as parameters. In the function, iterate through the array using pointer arithmetic, calculating the factorial for each element and storing the result back in the same array or a separate array. For calculating the factorial, you can use a simple loop or recursion. Finally, print or return the modified array with the factorials.


Implement a program to find out the reverse of an integer using recursive functions?

Note: You may need a larger data type, factorials become very big very quickly and may cause an overflow long factorial(int x) { if(x == 1) return 1; . return((long) factorial(x-1) * x);


Write a java program to find the factorial of a given number?

Here's a simple Java program to find the factorial of a given number using a recursive method: import java.util.Scanner; public class Factorial { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print(&quot;Enter a number: &quot;); int number = scanner.nextInt(); System.out.println(&quot;Factorial of &quot; + number + &quot; is &quot; + factorial(number)); } static int factorial(int n) { return (n == 0) ? 1 : n * factorial(n - 1); } } This program prompts the user for a number and calculates its factorial recursively.


Can you write an algorithm to find the greatest of three number using class?

Yes. But why?


Write the Pseudocode to find the factorial of a number?

Pseudo code+factorial


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.


How do algorithm to find the factorial of a number?

Factorial (n) = n * Factorial (n-1) for all positive values n given Factorial (1) = Factorial (0) = 1. Pseudo-code: Function: factorial, f Argument: positive number, n IF n&lt;=1 THEN RETURN 1 ELSE RETURN n * f(n-1) END IF