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 rectangles on a quilt are 2in. wide and 3in. long the perimeter of each rectangle is made by pattern of ref thread. if there are 30 rectangles in the quilt,
A biome that contains a layer of permanently frozen soil, called permafrost, would be classified as A. taiga B. desert C. tundra D. savannah E. temperate decidu
If y^8= 4 and y^7=3/x, what is the value of y in terms of x?
A test cross with an organism with a homozygous recessive genotype results in 50% of the offspring exhibiting the recessive trait. What is the genotype of the t
The sales tax rate is 8%. Estimate the tax on a jacket that costs $69.95.
How do you say little sister, little brother, older sister, and older brother in Korean? I hope someone who actually know Korean can answer this question.
If y^8= 4 and y^7=3/x, what is the value of y in terms of x?
Estimate the angle of elevation from the trailhead to the summit.
How can i solve this f:d->R f(x)=x at power2/x-1
Can someone explain lesson 6.3 math boxes in everyday math regarding the missing numbers on the number lines