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

What is the slope of (6,5) and (4,7)
· Palmer Raids · Red Scare · Harlem Renaissance · Sacco and Vanzetti Trial All of these terms are associated with which era? A) 1910s B) 1920s C) 1930s D
what is a scientific law?
The sickly brown falcon has scarcely eaten today.Which words in the sentence are adverbs?sickly; todaysickly; brownscarcely; todaysickly; scarcely
What is America duty according to wilson
All of the commandments in the Jewish religion are listed in the __________. A. tomb of Abraham B. books of the Torah C. Ten Commandments D. temple of Jeru
Which of the following best explains why the author chose the compare and contrast structure for paragraph 2?
Write a polynomial function of least degree with integral coefficients that have the given zeros. 4,-1,6 f(x)=x^3-9x^2+14x+24
Solve the inequality -1/2x>2 and write the solution using:
what is not typically present in works of the theater of the absurd? a. dialogue between characters b. a traditional plot c. implicit themes d. external conflic