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

what is anne franks charater traits
f(x)=3x-5 and g(x)=x^2+2, fins (f+g)(x)
How to build a robot
A sales team estimates that the number of new phones they will sell is a function of the price that they set. They estimate that if they set the price at x doll
list of arguments that support the US annexation of Hawaii
A model rocket is launched with an initial upward velocity of 54 m/s. The rocket's height h (in meters) after t seconds is given by the following.
What is the recursive rule for the sequence? 3, −1, 1/3, −1/9, ...
What is the replacement word for expensive
Which one of the following pairs of sets has no members in common? A:{all composite numbers} , {all odd numbers} B:{all multiples of three} , {all multiples of
The unit dosing machine packages medication based on the