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

Aside absorbing water and nutrients, what other functions do the roots serve?
An infant is 32.625 inches (in) long. Write this as a common fraction.
what are the components of blood?
7 facts about water of southwest region
How do we call a very small video,that is repeating unlimitedely
Simplify (2x + 3)(x – 4) = ?
Compare the various effects that alcohol has on the mind and body at two different blood alcohol concentrations.
Aside absorbing water and nutrients, what other functions do the roots serve?
what are the 2 types of behavioral responses??
What is 4p-13p-p=-150 More 2 step equations. I don't get this one at all