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

james school is selling tickets to the annual dance competition. On the first day of ticket sales the school sold 9 senior citizen tickets and 8 child tickets f
) What strategy was eventually successful to help the North win the Civil War?
How does matter cycle and energy flow through the rock cycle?
1. Ang tawag sa hanay ng mga cells sa worksheet ng spreadsheet na nakahanay ng pahalang. Ito ay may numero kaliwang bahagi nito.​
In this topic, you will explore light and colour. How does light give objects their colour ? Record your ideas below.
Give two reasons why producers had to precede animals in evolution.
The Iced Tea Debate: If the temperature of the iced tea___________, then the iced tea_____________.
what is folding geography
what does a paleontologist study?
How does the subplot involving the mulberry tree anecdote enhance Trevor Noah’s memoir?