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

The scale of a map is 7ft = 14.4 mi map: ________ ft actual: 24.6 mi
In a re survey 3 out of 8 people preferred the vanilla yogurt over the strawberry yogurt if there were a total of 120 surceyed how many liked the vanilla yogu
Please explain what is the menu cost,and what does it Include
Find the sum of the hundreds digit and the tenths digit in the number 1,764.823.
Which type of manager would most likely work with the National Forest Service?
A cow and a frog have similar bone structures in their forelimbs. Both have phalanges, radius, ulna, and humerus bones. However, the cow and frog are animals w
What is an irrational number between 5.2 and 5.5
If your annual pay is $36,010, what is your biweekly pay based on 26 biweekly paychecks?
PLZ HELP. THIS IS EASY PROBABLY HAHA. WILL GIVE THANKS AND BRAINLIEST
To which physical sense does the author appeal in describing Old Lady Chong’s age? touch smell hearing taste