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

Irrational Numbers. Am I correct?
It was “assumed” that the windmill plans had been rubbed off the floor. How does Orwell use this word to describe the animals’ level of thought? This is the sec
Which sympathetic pathway is responsible for the prolonged effect of the "fight or flight" response?
What is the key difference between a professional networking site and a social networking site?
Which of the following pairs of elements is most likely to form an ionic compound? Calcium and iodine, nitrogen and phosphorus, fluorine and sulfur, it sodium a
What healthful condiments might you suggest to take the place of pancake syrups and sugary jellies for breakfast?
Which of the following statements describes the process by which Oklahoma’s mountain ranges are changing? A. Erosion is causing them to increase slightly in ele
Men with symptoms of __ may notice a penile discharge, a burning sensation when urinating, or pain and swirling in one or both testicles
Solve and graph (Look at pic.)
Explain how both biochemical oxygen demand and chemical oxygen demand are measured. microbiology