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 might a tyrant say to a citizen who are asking for democracy
What happened in 1853 that showed Japan the importance of industrial power?
What legacy did World War 1 leave behind?
Dory can run 3.25 miles every hour
If the acetylene tank contains 37.0 mol of C2H2 and the oxygen tank contains 81.0 mol of O2, what is the limiting reactant for this reaction?
Simplify the expression. 3n - 5 + 2n + 4
Use The distributive property to write an expression equivalent to 5 x (3 +4)
The scale of a map is 1 inch equals 500 miles city A 650 miles from city C how far is it to distance on the map
The currently used binomial nomenclature was developed by _____. Ray Linnaeus Aristotle
Describe some possible impacts of adding or removing a species from and ecosystem