answersLogoWhite

0


Best Answer

double factorial(double N)

{

double total = 1;

while (N > 1)

{

total *= N;

N--;

}

return total; // We are returning the value in variable title total

//return factorial;

}

int main()

{

double myNumber = 0;

cout << "Enter the number: ";

cin >> myNumber;

cout << endl << "Factorial of N is: " << factorial(myNumber);

return 0;

}

User Avatar

Wiki User

16y ago

Still curious? Ask our experts.

Chat with our AI personalities

LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
More answers
User Avatar

Wiki User

14y ago

By the definition of a factorial, multiply all numbers up to the number given.

For example (using Java code):

int number = 5; // Sample value

long factorial = 1;

for (int i = 1; i <= number; i++)

{

factorial *= i;

}

System.out.println(number + "! = " + factorial);

User Avatar

Add your answer:

Earn +20 pts
Q: Programming to calculate a factorial number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a recursive procedure to compute the factorial of a number?

#include &lt;iostream&gt; using namespace std; int main() { int i, number=0, factorial=1; // User input must be an integer number between 1 and 10 while(number&lt;1 number&gt;10) { cout &lt;&lt; "Enter integer number (1-10) = "; cin &gt;&gt; number; } // Calculate the factorial with a FOR loop for(i=1; i&lt;=number; i++) { factorial = factorial*i; } // Output result cout &lt;&lt; "Factorial = " &lt;&lt; factorial &lt;&lt; endl;


How do you write a program that calculate factorial in javascript?

factorial number Var num= prompt(&quot;enter any number &quot;); Var i=1; Var fact=1; for(i=1;i


Write an algorithm to print the factorial of given number and then draw the flowchart?

write an algorithm to print the factorial of a given number and then draw the flowchart. This looks like someones homework, defiantly someone looking for the easy way. When it comes to programming, the more you do the better you get. Experience counts (making your own mistakes and learning from the mistake).


Write the Pseudocode to find the factorial of a number?

Pseudo code+factorial


How do you create factorial program in qbasic?

since factorial is for example , the factorial of 5 = 5 (5-1)(5-2)(5-3)(5-4) that means the last number to subtract from 5 is 4 , which is (n-1) ie the factorial of any number is (n-0)(.............)(n-(n-1)) to write this , 5 REM to calculate the factorial of any number 6 DIM fac AS INTEGER LET fac = 1 10 INPUT "enter the number to find its factorial "; a ' variable a 15 FOR b = 0 TO (a-1) 'numbers that will be subtracted from the " a" 20 c= a -b 'each number in the factorial calculation 25 fac = fac * c 'to compute each multiplication in the factorial 30 NEXT b 35 PRINT 'to leave a line 40 PRINT fac 45 END note this due to some unattained raesons works for numbers 0 to 7

Related questions

What is the most efficient way to implement a factorial algorithm in a programming language?

The most efficient way to implement a factorial algorithm in a programming language is to use an iterative approach rather than a recursive one. This involves using a loop to multiply the numbers from 1 to the given input number to calculate the factorial. This method is more memory-efficient and faster than using recursion.


How many zeros are possible factorial 10 to the power factorial 10?

To calculate the number of zeros in a factorial number, we need to determine the number of factors of 5 in the factorial. In this case, we are looking at 10 to the power of 10 factorial. The number of factors of 5 in 10! is 2 (from 5 and 10). Therefore, the number of zeros in 10 to the power of 10 factorial would be 2.


Write a recursive procedure to compute the factorial of a number?

#include &lt;iostream&gt; using namespace std; int main() { int i, number=0, factorial=1; // User input must be an integer number between 1 and 10 while(number&lt;1 number&gt;10) { cout &lt;&lt; "Enter integer number (1-10) = "; cin &gt;&gt; number; } // Calculate the factorial with a FOR loop for(i=1; i&lt;=number; i++) { factorial = factorial*i; } // Output result cout &lt;&lt; "Factorial = " &lt;&lt; factorial &lt;&lt; endl;


How do you write a program that calculate factorial in javascript?

factorial number Var num= prompt(&quot;enter any number &quot;); Var i=1; Var fact=1; for(i=1;i


How do you calculate factorial without calculator?

Factorial is calculated by taking the number and multiplying it continually by 1 less than that until you finally multiple by 1. For example 6! = 6x5x4x3x2x1 = 720


What is factory or factorial?

Factorial for number N is N x N-1 x N-2 X N- (N-1). e.g. if you need to calculate factorial for 5 then compute 5 x 4 x 3 x 2 x 1.


Can you provide some running examples to illustrate the concept of recursion in programming?

Recursion in programming is when a function calls itself to solve a problem. For example, a common recursive function is calculating the factorial of a number. Here's an example in Python: python def factorial(n): if n 0: return 1 else: return n factorial(n-1) print(factorial(5)) Output: 120 Another example is the Fibonacci sequence, where each number is the sum of the two preceding ones. Here's a recursive function to calculate the nth Fibonacci number: python def fibonacci(n): if n 1: return n else: return fibonacci(n-1) fibonacci(n-2) print(fibonacci(6)) Output: 8 These examples demonstrate how recursion can be used to solve problems by breaking them down into smaller, simpler subproblems.


Write an algorithm to print the factorial of given number and then draw the flowchart?

write an algorithm to print the factorial of a given number and then draw the flowchart. This looks like someones homework, defiantly someone looking for the easy way. When it comes to programming, the more you do the better you get. Experience counts (making your own mistakes and learning from the mistake).


What is the time complexity, in terms of Big O notation, for calculating the factorial of a number?

The time complexity for calculating the factorial of a number is O(n), where n is the number for which the factorial is being calculated.


What is a program in c to calculate factorial of number?

First of all we will define what factorial is and how to it is calculated.Factional is non negative integer. Notation would be n! It is calculated by multiplying all integers from 1 to n;For example:5! = 1 x 2 x 3 x 4 x 5 = 120.Note: 0! = 1Small C program that illustrates how factorial might be counted:#include int factorial(int num);int main() {int num;printf("Enter number: ");scanf("%d", &num);printf("Factorial: %d\n", factorial(num));return 0;}int factorial(int num) {if (num == 0) {return 1;}return num * factorial(num - 1);}Testing:Enter number: 5Factorial: 120Enter number: 0Factorial: 1


Write the Pseudocode to find the factorial of a number?

Pseudo code+factorial


What is 1000000000 factorial?

The factorial of a number is the product of all positive integers up to that number. The factorial of 1000000000, denoted as 1000000000!, is an extremely large number with 5,565,709,298 digits. It is practically impossible to calculate or write out the exact value of such a large factorial without the use of specialized software or mathematical tools.