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

What happens to blood pressure if your blood is thicker?
What kind of issue requires a 2/3 vote in the senate?
What is the value of X? show all of your work
How did the jamestown colonist affected
what is 10 times as much as 430?​
How did life change for women during World War II?
How does Chaucer describe the Pardoner?
Which of the following reduced the demand stimulus effects of the fed's low interest rate policy pursued during, and after, the financial crisis of 2008-2009? a
The military dictatorship inviolently reacted to the opposition of the Maya, who demanded greater rights for their native population. The genocide inresulted fr
40 pts Simplify: (4a – 3)2 a. 8a2 – 24a + 6 b.162a – 12 + 9 c.16a2 – 24a + 9 d,16a2 – 9