Question #3310

Write a program to calculate the factorial of given number.

Expert's answer

#include <iostream>

using namespace std;

double calculate_factorial (double number)

{

if (number == 0) return 1.0;

return number * calculate_factorial(number-1);

}

int main()

{

double number = 8;

double factorial = calculate_factorial (number);

cout << "The factorial is " << factorial << endl;

return 0;

}

using namespace std;

double calculate_factorial (double number)

{

if (number == 0) return 1.0;

return number * calculate_factorial(number-1);

}

int main()

{

double number = 8;

double factorial = calculate_factorial (number);

cout << "The factorial is " << factorial << endl;

return 0;

}

## Comments

## Leave a comment