A
arnuld
it runs fine. any advice for the improvement:
/* C++ Primer - 4/e
*
* exercise 7.20
* STATEMENT:
* write a programme to find the factorial of an int.
* use an iteratice function.
*
*/
#include <iostream>
long double find_factorial( int num ) {
/* maximum value of 32 bit int is 32768. so we need to use
long double to store its factorial value, but still for any values
above 1754 i get "inf" as output. i dont't have any problem with that
kind of output as i have successfully created the iterative version
of the factorial function.
*/
long double facto = 1;
for(int i = num; i != 0; --i)
{
facto *= i;
}
return facto;
}
int main()
{
std::cout << "Enter the number: ";
int i;
std::cin >> i;
std::cout << "Factorial of "
<< i
<< " = "
<< find_factorial( i )
<< std::endl;
return 0;
}
/* C++ Primer - 4/e
*
* exercise 7.20
* STATEMENT:
* write a programme to find the factorial of an int.
* use an iteratice function.
*
*/
#include <iostream>
long double find_factorial( int num ) {
/* maximum value of 32 bit int is 32768. so we need to use
long double to store its factorial value, but still for any values
above 1754 i get "inf" as output. i dont't have any problem with that
kind of output as i have successfully created the iterative version
of the factorial function.
*/
long double facto = 1;
for(int i = num; i != 0; --i)
{
facto *= i;
}
return facto;
}
int main()
{
std::cout << "Enter the number: ";
int i;
std::cin >> i;
std::cout << "Factorial of "
<< i
<< " = "
<< find_factorial( i )
<< std::endl;
return 0;
}