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

How long does interphase last?
Is Glass a good conductor of heat? is Metal a good conductor of heat? is wood a good conductor of heat
how do i persuade students to enter the school talent show? i have to write it as an article in the school magazine.
why do the two elements silver and iron have different properties?
the temperature on mars ranges widely from -207 f to 80 f find the average of the temperature extremes on mars
Solve the following equation 3m^2=3-8m. Find both values
Trent and Chris are musicians, and they recently played a concert for 20,000 fans. The rectangular venue measured 87 yards by 57 yards. What was the approximate
why does methane have a low boiling pint?
what type of bond is methane?
written in simplest form, the expression (x^2)(y^2)-9 over 3-xy is equivalent to 1. -1 2. 1 over 3+xy 3. -(3+xy) 4. 3+xy Please show work