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 far does Franklin Roosevelt deserve his reputation as one of the greatest US presidents?
During the evolution of life on Earth, the photosynthetic organisms initially responsible for raising atmospheric oxygen concentrations from less than 1 percent
THE EXPRESSION (TAN THETA) (CSC THETA) IS EQUAL TO?
What is does the phrase foe to ambition.
How do you pronounce the letter "X" in Spanish?
You are standing 1 meter from a squawking parrot. If you move to a distance three meters away, the sound intensity will be what fraction of its original value?
Solve the equation log 6x - 3 = -4
A number is divided by 32 is 96. What is the number?
which of the following organisms feeds on the largest variety of producers
translate into an equation. Five times the sum of twice a number, x, and six is thirty. Find the number.x = Translate into an equation. The difference b