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

Information based on opinions is valid. a. True b. False
do mountains really grow?
the measure of how demand changes after price adjustments is called (a)elastic, demand (b)inelastic demand, (c)the law of demand, (d)consumer demand
In terms of the proportion of college graduates, the least educated religious group is
Location plays a role in wetland type, but is not the sole determining factor. true or false
Which of the following is NOT one of the responsibilities of the Federal Reserve? ASupervising the Reserve banks BMaintaining a stable banking system CSetting t
Is the following an example of a simile, metaphor, paradox, or personification? The rumbling storm sounded like a freight train headed our way. A. simile B. me
The Dionysia was a religious festival honoring which Greek god? Dionysus Zeus Athena Teiresias
The _______ wrote a petition to King George declaring Parliament couldn't pass laws on the colonists without representation by colonists.
Which type of organic molecule is an amino acid