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

at end of spanish american war all was true about cuba except
how to solve with exponents and negatives
someone put $15,000 in the bank 3% of 1500 thousand dollars in one year
All people are promised their equality by the Declaration of Independence it also promises the right to pursue happiness
Over time, pollution generally leads to which of the following? A.healthier plants B.healthier animals C.a decrease in population of some plants and animals D.a
who lead the rebellion against shi huangis harsh rules
(2-2)(34 (2-3)(32)2?2,(34-3va2Which is the simplified form of the expression023534836 48230 30-80236348(30000
what is the volume of a rectangular prism with a height of 7 units, a width of 5 units, and a length of 8 units
why did the europeans want to leave east asia in the 1400s
The table shows the price for different numbers of pudding cups: Number of Pudding Cups Price (in dollars) 2 6 4