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 characteristics do tragric heroes share?
Which of the following is a true difference between prokaryotic and eukaryotic cells? a. Eukaryotic cells have true nuclei. b. Eukaryotic cells are smaller. c.
If two objects at different temperatures are in contact with each other, what happens to their temperatures?
5.39 repeating decimal as a mixed number
What is the unit rate for 14 lb for $2.99
what part of the brain moitors bodybtempreture
Write an expression for the calculation double 7, multiply 3 and 1, and then subtract the second number from the first number
3 - 3 × 6 + 2 = what
how can i show my work for 2x-4= -10+x
3(a + b) = 3a + 3b is an example of which algebraic property? Distributive Property Associative Property of Addition Commutative Property of Addition Symmet