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

Someone hmu I’m bored Also what’s 2+2
A plane cuts a pyramid as shown in the diagram. What is the shape of the cross section A. Hexagon B. Pentagon C. Square D. Triangle
Can someone answer this question please answer it correctly if it’s corect I will mark you brainliest
how to find the area of a trapazoid
. A line has a y-intercept of 4 and passes through the point (2,0). Write the equation for this line.
Which layer is the YOUNGEST?
Which of these court cases MOST LIKELY helped accused people who cannot afford lawyers get them from the government? A) Roe v. Wade B) Miranda v. Arizona C) G
“As an airplane’s propellers spin, they give the airplane a forward force (thrust). […] As an airplane moves forward, the shape of its wing creates lower pressu
Plz answer ASAP! I’ll mark Brainiest. For the right triangles below, find the exact values of the side lengths d and h. If necessary, write your responses in si
Can you help me with my math?