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

Who assisted Chinese rebels in overthrowing the Ming dynasty and installing the Qing dynasty? A. Sillas B. Mongols C. Manchus D. Koreans
Billy goes to a car rally. He keeps a note of the race times of the cars in minutes: 122,133,142,154,122,156,134. What is the range of the times?
Before the Agricultural Revolution, many people lived in rural areas because
what is the diameter of the geosphere
Reincarnation is a Hindu belief that the individual soul... a. Is reborn in a different form. b. Serves the god Vishnu. c. Is itself a god. d. emanates from
5 is less than a number y is under 20
Simplify the expression. 4 + 2 • 8 a. 48 b. 40 c. 20 d. 18
write in exponent form and word form 10x10x10
What is a society ruled by religous leaders called?
graph the linear equation x-y=4