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

Glucose can be used directly in its raw form for energy in animals A. True B. False speaker notes
the highest or lowest point on a parabola is called
Just the first 6 questions or everything i’ll give brainliest or something.
:) 1. Outline two differences between a moving coil -coil and a moving-iron instrument.​
Can anyone help me with this please ? I’ll mark you as a brainliest
State one problem which pollution can cause To the environment
how to work out a mixed number?
an alkyne with molecular formula c5h8 is treated with excess hbr, and two different products are obtained, each of which has molecular formula c5h10br2.
HELP!!! Subtract. 3 2/3−(−1 1/12) Enter your answer as a simplified mixed number by filling in the boxes.
add the sum and difference identities for sin x to derive 1/2 [sin(x+y)+sin(x-y)]=sin x cos y