Can someone please explain the math involved here with the function int factorial(int number). I can not seem to understand why int product =1 and how this particular for loop works to output the math of factorials and square roots. Thanks.
[code]
#include<iostream>
#include<cmath>
using namespace std;
int factorial(int number);
/* MAIN PROGRAM: */
int main()
{
int whole_number;
cout << "Enter a positive integer:\n";
cin >> whole_number;
cout << "The factorial of " << whole_number << " is ";
cout << factorial(whole_number);
cout << ", and the square root of " << whole_number << " is ";
cout << sqrt(whole_number) << ".\n";
return 0;
}
/* END OF MAIN PROGRAM */
/* FUNCTION TO CALCULATE FACTORIAL: */
int factorial(int number)
{
int product = 1;
and the reason for no initiation of the for loop allows for any starting input? Also I get that now, thanks, that makes sense because once the loop reaches zero it will make the loop false and end it because 5x4x3x2x1x0 = 0.
However, what about
int product=1;
Why do you need to specify this?
and what about the square root function? Where is it being calculated in this code?