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

Eduardo: ¿Quieres ir al cine hoy? Fernando: Sí. _____ a la una. Saldrán Saldremos Saldrás Saldré
In the reaction Mg (s) + 2HCl (aq) -> H2 (g) + MgCl2 (aq), how many grams of hydrogen gas will be produced from 300 milliliters of a 4 M HCl in an excess of
In writing a short story about having dinner , how can you narrow your topic
U.s. foreign policy in the 20th and 21st centuries has been
what is the cross section created when a slice is made perpendicular to the two bases of a cylinder
The privileges and immunities clause of the Articles of Confederation stated that a citizen of one state who moves to another state is entitled to the rights of
Which of the following is a statistical question? a.Who is your favorite fantasy author? b.Do you like fantasy novels? c.What is your favorite fantasy novel? d.
List the coordinate point labeled "G"
Which list orders the oceans in size from largest to smallest?
use the polygon tool to draw a right triangle with hypotenuse RS