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

find the product or quotient for each. simple form 5/9 divide 5/6
Which of the following is a case of frictional unemployment? A. Timothy is looking for a job where he can apply his expertise in computer programming. B. Thom
A painter used 3/8 gallon of paint for one job and 1/3 gallon for another job. How many gallons of paint did the paint use for both jobs. A) 4/11 gal B) 17/24 g
Need help on this lovesss
15. BCD are two similar rectangles. AGD and In the figure, AEFG and ABCD are two similar rectan AEB are straight lines. If AE: AB= 3:5, find the ratio o of the
Please be quick! I need this as soon as possible!
when is the day of preparation in Mexico​
I need help pleaseeeee guysss 40 points
A line that includes the points (-4,0) and (f,9) has a slope of 9. What is the value of f? f= Help Hurry!
Can someone pls help me with the essay pls I would really appreciate it