Swsan7715 Swsan7715
  • 03-06-2021
  • Computers and Technology
contestada

3- Write a C++ program by using for loop that will ask for an integer as a parameter and display its factorial. Hint factorial (5)=5^ * 4^ * 3^ * 2^ * 1

Respuesta :

tonb
tonb tonb
  • 03-06-2021

Answer:

#include <iostream>

using namespace std;

int main() {  

 int n;

 cout << "Enter number: ";

 cin >> n;

 int fact = 1;

 for(int i=2; i<=n; i++) {

   fact *= i;

 }

 cout << n << "! = " << fact << endl;

}

Explanation:

Another cool way to do this is to write a recursive function. But here specifically a for loop was asked.

Answer Link

Otras preguntas

Cuanto vale la y en matemáticas
PLEASE HELP!! Whats the lifestyle or entertainment in The Odyssey? (I need it for a newspaper project so please answer w a good explanation)
-15p+32p please awnser its rsm hw
what is the principle of foreign policy of Nepal​
-15p+32p please awnser its rsm hw
If x +2 is a factor of p(x) =x²-kx +7, thrn find the value of k.Also,find the other factor of the polynomial ?​
The sun ____ in the East.​
Write the slope-intercept form of the equation of the line through the given point with the given slope. through: (2,-2), slope = -5/6
A sentence that asks a question ends with a period. True False
(1) When we call someone “pig” or “swine,” we do not mean it as a compliment. (2) But pigs do not deserve to be used as a symbol for an insult. (3) They are pro