terrifunk7546 terrifunk7546
  • 22-09-2017
  • Computers and Technology
contestada

Write a program that lets a user enter n and that outputs n! (meaning n*(n-1)*(n-2)*...*2*1). hint: initialize a variable totalvalue to n, and use a loop variable i that counts from n-1 down to 1.

Respuesta :

Аноним Аноним
  • 30-09-2017
//  This code snippet calculates n! and stores the answer in the variable p.
// Handle 0! = 1 separately.
if (n==0) {
   p = 1;
}
else {
// Initialize p = n
p = n;

// While loop
while (n>1) {
      p = p*(n-1);
      n = n-1;
     }
}

Answer Link

Otras preguntas

When does James Gatz change his name ? Why ?
Mr. Rowley has 16 papers and 14 exit tickets to return. Ms. Rivera has 64 homework papers and 60 exit tickets to return. For each teacher, write a ratio to repr
15=7-|2x| Solve for x in this absolute value equation.
is 1/7  rational or irrational
what is .54 repeating as a fraction
How were Serbia''s actions in Kosovo similar to its actions in Bosnia and Herzegovina ?
Find the coordinates of the midpoint of a segment having the given end pointsC. C(9,5),D(17,4) I can't figure it out.
Which term is used for the tendency of an object to resist a change in its motion? A. acceleration B. displacement C. momentum D. inertia
What is the main idea of wizard of oz?
Identity true statements about quadratic function y = ax^{2} +bx+c, where a =/= 0. (1) It reaches either maximum or minimum at the vertex. (2) Its domain consis