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

the strongest characters in the world are obsessed with me
Which of the following is NOT a way to increase adolescents' engagement with their schools? ut Select one: a. encourage extracurricular activities on b. increas
What are the quantities and units of the formula of distance in accelerated motion?
Local rules we must follow are sometimes known as what? Policies Guidelines Ordinances
there are 30 men and 15 of them have facial hair how much percentage would that be​
why did marcellus bring horatio to the night watch
¿Cuál personaje desempeña el rol del "gracioso" o "donaire" en el fragmento?
can someone please help me i need the sales analysis for covergirl. please help it's due in 30 minutes
how can you simplify integer expressions that contain more than one operation? answer quick pls
A new hotel was built with r rooms. The first weekend it was open, 3/5 of them were reserved. Which of the following expressions represents the number of rooms