/* Program 3.3.1 from C++ Programming Lecture notes  */

/* Author: Rob Miller and William Knottenbelt
   Program last changed: 30th September 2001 */

/* This program calculates the factorial of a given positive integer. */ 

#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;
	
	for ( ; number > 0 ; number--)
		product *= number;
		
	return product;
}
/* END OF FUNCTION */
