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

Slave rice cultivators commonly worked by the __________, which involved a specific assignment for a day's work.
please explain your answer (if u dont have time thats ok too)
80 to 60 as a fraction
identify the type of function represented by f(x) 4 2^x
Help please thank you (next)
PLEASE HURRY!!!! DUE TODAY!!! can someone please write me a 2-3 paragragh essay on the diferences and similarities of the movie the lottery and the story
Describe the attempts of the various European colonies to convert native peoples to their belief systems.
what is negative are positive A+B
At maximum speed, an airplane travels 2460 miles against the wind in 6 hours. flying with the wind, the plane can travel the same distance in 5 hours. what is t
how is human activity affected by sinkholes