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

Write one of each type of sentence. declarative, interrogative, exclamatory, imperative, simple, compound, complex, using “however,” using a semicolon
12. Classification can increase your ______of how things may be related to one another. what goes In the blank ?​
Les reponses s il vous plait
What is m∠2 if m∠1 is 46 degrees
A student has scores of 57, 58 and 63.25 on his first three test. He needs an average of at least 60 to a grade of D what is the minimum score that the student
Identify a condition for a patient and determine the clinical pathway that the patient will take. Identify at least three types of health services (for example,
how to solve this inequality X^2(1-X)​
June has $1.95 in dimes and nickles. She has a total of 28 coins. How many of each type of coin does she have?
f(x)+f(x)+f(x)= help me with this problem please
HELPP!! i need the answer to this i need it do e by the end of the dayyyy