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

The passage of the Fifteenth Amendment in 1869 prompted the formation of two major suffrage organizations because A. it marked a great success for the abolition
"And suddenly I realized that I should have to shoot the elephant after all. The people expected it of me and I had got to do it; I could feel their two thousan
Find the sum of a finite geometric series. Amanda teaches the art of quilling to 4 students. These students each teach the art of quilling to 4 other students.
Potassium and iodine have formed a bond. Prior to this the potassium gave up an electron. It became a _____ Positive ion Neutral atom Negative ion Shared ion
Find the sum of a finite geometric series. Amanda teaches the art of quilling to 4 students. These students each teach the art of quilling to 4 other students.
Which are are the roots of the quadratic function F(q)=q^2-125?
how do I solve this?
The process by which court decisions have required the states to follow parts if the bill of rights based on the use or application of the fourteenth amendment
Graph the function f (x)= x+2
Which expressions are equivalent to the one below. Check all that apply. 49^x