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

5.4 5.400 less greater
what does alignment mean in dance?
factor the question=x^2-14x+49
Write 0.632 in 2 forms
Death Valley has an elevation if -282 feet relative to sea level. Explain how to use absolute value to describe the elevation of Death Valley as a positive inte
For what reason was the "Union Party" created? Who were its candidates?
give me a sentence that has the words prosper and profit
Analyze how scientific thhought changes as new information is collected
describe the relationship between the value of a dollar and the value of a dime
arrange following numbers in increasing order 2.3,45.1,18.735,0.9862,7