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

how to solve x to the power of 2 = 14
is a piece of cloth a point, line, or plane?
If 604-72=___,then 532+___=604.Explain the process of checking your work.
A crime suspect fled the scene when police officers entered the building. How far could he run in 10 minutes if he can run 5 miles per hour?
which property you used.64+58=                    +64
is a piece of cloth a point, line, or plane?
how to solve x to the power of 2 = 14
The gram formula weight of phosphoric acid is 98.00 g/mol, and the density of 85.0% phosphoric acid is 1.685 g/mL. Could you describe how ...
How many magnesium ions are present in 5.36 x 10-4 mol of magnesium iodide?
Write y= 3/4x + 1/2 in standard form. Thanks in advance. Also, could you please briefly explain how you did it, because these questions confuse me. Thank you. A