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

How could y squared be rewritten?​
Which of the following best describes artificial selection as compared to natural selection? In natural selection, the passing on of traits is determined by hu
In 100 words write about a holiday you like most of all. about-New year
Describe how to transform the quantity of the fifth root of x to the seventh power, to the third power into an expression with a rational exponent. [tex](5\sqrt
Convert to fractions and write in simplest form. A) 0.02 B) 12% C) 0.5% D) 1.12
Can anyone please help me answer this Math Question ? Soon as possible ! Monique went to the emergency room for stitches after she accidentally cut her hand wh
Why did France colonize Vietnam?
What is the solution to the equation −5p=10 ?
The evidence-based management approach is based on.
When observing live organisms, the specimen is prepared with a drop of liquid on which a coverslip has been placed. This is called a .