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 federal minimum wage law requires that most workers be paid at least $5.15 per hour. a governor of a small industrial state, in which the standard of livin
Which religious ethnicity did german nazis' send to death camps?
An air mass that controls the weather in a region for a prolonged period is sometimes referred to as _____ weather.
Our ability to fulfill our potential through greater self-understanding is part of the ________ approach to personality.
In a democratic government, majority rules, but the rights of the minority are also considered. a. True b. False
Calculate the mass in grams of iodine (i 2 ) that will react completely with 20.4 g of aluminum (al) to form aluminum iodide (ali
How long does a dog with parvo take to recover?
if you drop a 50 gram piece of metal with a temperature of 125° Celsius into 1000 grams of water at 20° Celsius, what best describes what would occur?
Jaspar is rushing to catch the 13:12 train from Edinburgh to London. The train leaves once an hour at 12 minutes past. How long will Jaspar have to wait if he a
Solve the following linear equation 7(x - 2) = 4(x + 1) - 21