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 size of the program counter for an avr that has a 1 kbyte rom capacity?
What’s 11/15 times 1/75
Write your question here (keep it simple)?
If an x-ray has a wave link of five in M what is its frequency answer and years of Hz
How far a wave travels in one second is a measure of wave what?
Which of the following is NOT a characteristic of the world’s earliest civilizations? Group of answer choices religion social structure food surplus militar
Find+the+positive+value+for+α+if+the+radius+of+the+circle+3x^2+3y-6αx+12y-3α=0+is+4
What is the image of the point (5,-6) after a rotation of 90 counterclockwise about the origin.
find S5 when Sn = 40 - 8n
THE DU O ryms Quiz American Government IS-RCCSD JDHS 19-20 1. Why did many states propose amendments or changes when ratifying the Constitution? O The framers o