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

Joshua has 200 tiles to put on his floors. Each tile has an area of 1 square foot. Which rooms can Joshua cover with tile? Justify your answer with words and ca
give me some good good anime recs with gore.
PLEASE HELP ITS DUE IN 7 MINUTES!​
What was the Treaty of Indian Springs?
what are the advantages of regional level profession ? Discuss​
Write the balanced chemical equation for the dissociation reaction of thiosulfuric acid
7th-grade math help me, please :(
does any body like lecrae? i do
Which of the following best describes the proper use of a “Works Cited” page? A. A Works Cited page is not needed if you paraphrase your research B. A Works Ci
For a function g(x), the difference quotient is 6^x+h+3 - 6^x+3 /h What is the average rate of change of g(x) on the interval from x = –2 to x = 1? A. 30 B. 36