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

1. Please select each piece of information needed to calculate a real exchange rate. a. nominal exchange rate b. foreign price in foreign currency c. domesti
What is the vertex of the parabola?
What leads to violence and what will be the best way to cure violence
plzs help wnd how do u give brainleist im new
how much are nfl players fined for throwing a football into the stands
someone pls help me;-;
100 POINTS TO PERSON WHO ANSWRS IN 5 MINUTES ALSO BRAINLIEST Choose the appropriate word to finish the sentence. Manuel es muy buen alumno; siempre hace ____ a
What is the solution to ( 4 * 10 ^ 3 ) x ( 3 * 10 ^ 4 ) written in scientific notation?
-4|x +3| = -28 I can’t figure it out ):
this planet contains the largest mountain in the solar system.