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 the reduced radical form of each expression?
if the atmospheric is 103.2 kpa and the absolute pressure at the bottom of the tank is 230 kpa. what is the specific gravity of olive oil?
Find the quotient and the remainder
Abigail was delivered by emergency caesarean section at only 25 weeks gestation. She was taken to the neonatal intensive care unit (NICU) where she was fed intr
What is the history of cough syrup
Article “The importance of family game nights” by katarzyna radza
Who is Christina Rivera Garza?
Jin met Pat on September 8 at Queen Bank. After talking with Pat, Jin decided she would like to consider a $9,000 loan at 1012% to be repaid on February 17 of t
Rohan bought a motorbike for rupees 5675 and spent 453 rupees on its repiar. Then he sold it for 1265. Find out the profit or loss he made.​
State the name of the reaction for the traditional making of lime?