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

I'll give brainliest to first person that answers :)
What does x2-5x+6=0 equal?
Which of these are part of a basic plot structure? Select three options A. Exposition B. Climax C. Character motivation D. Falling action E. Theme
5 sentences about family
tìm a giao b , a hợp b .a hiệu b , b hiệu a a) -00;7);{2;4}
The total cost of online streaming is proportional to the number of months. What is the constant of proportionality
What number goes on top? 16 17 7 9 8 4 5 3 3 The blank would be
What is the verb from congestion?
someone please help me. Im giving brainliest!!
click on screenshot and please answer