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

Which one of the following is a characteristic of a metal? A. Changes the color of litmus paper to red B. Conducts heat readily C. Reacts with bases to produce
A _____ is a horizontal stem that can divide and grow in several directions at once.
What did chloroplasts evolve from according to the endosymbiotic hypothesis?
Forme des familles de mots en completant le tableau: Dans le tableau il y a deja: Nom=Terreur Adjectif= craintif, effeoyable Verbe= s'affoler, stupéfier Merci s
A decimal is a fraction that has a denominator of 100. always sometimes or never?
To create a tone, you would mix a hue with a. white. B. gray. C. black.
Marty sensed that his baseball team was in trouble. would this be a noun, adjective, adverb, or verb?
In a nuclear power plant, excess heat is: A. released into the air b. reused by the nuclear reactor c. absorbed and removed by water d. used to power turbines
Probably the most lasting contribution of Napoleon's rule was A. his understanding of the role of the military. B. abolishing the aristocracy and subordinating
Factorise&expanding Can you factorise 81n-45