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

What is the Difference between Research and Investigation???
How do you find the interior angles of a triangle, if only one is given angle is given to you?
If the probability of giving birth to a boy is 0.52, what is the approximate probability of giving birth to 4 consecutive boys?
Why does 2 pi divided by 1/3 equal 6 pi?
If the probability of giving birth to a boy is 0.52, what is the approximate probability of giving birth to 4 consecutive boys?
What was the Islamic Golden Age?
Give 3 examples to show work being done.
The copper wire and bulb is connected in a series with 220 V electric supply. Why only an electric bulb glows where as the copper wire remains the same.Give REA
Alison wants to find out how much time people spend reading books. She is going to use a questionnaire. Design a suitable question for Alison to use in her ques
if i got 68 correct on my math test and the total is 85 what is the score?