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

in 1980, Asian immigration outnumbered European immigration. A: true B: false
What message does Amy Tan's description send?Her relatives are hungry, and Robert's family is not.Her relatives are eager, and Robert's family is hesitant.Her r
eight and three tenths in decimal form
Is sportsmanship as important as athleticism
what does level d mean on iready? if you know what i am talking about than put your aswer in the box plz
find the x-intercept of the line -4× - 2y = 16​
can someone please help me figure this out??
How many miles of NaBr will be produced when 3.33 mol of bromine reacts according to the following equation
what does the public sector provide that the private sector does not?
!!PLEASE HELP!! A man is at present 7 times as old as his daughter. In 10 years from now he will be 3 times as old as his daughter will be then. How old is his