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

Which expression is equivalent to 5x+10y-15
glycogen, starch, and cellulose are examples of​
Evalúo mis procesos de aprendizajeCompleta el gráfico de reflexión metacognitiva que aparece a continuación. Debesseñalar lo que aprendiste, lo que necesitas re
Does the shadow tell you that the girl is translucent, transparent, or opaque? What inference can you make? also explain it Subject Science​
Omar went back to school shopping and bought a shirt for $28.75 and a pair of pants for $19.25. He paid 8% in sales tax. How much did Omar spend on the shirt an
Find the measure of the missing angle. 130° 25° ?
Simple explanation of string theory, please don’t plagiarize.
What is the name of the holiest city of Islam? Muslim Mecca Medina Kaaba Hijrah
need help understanding this!
What country started WWII? Due​