|
|
|
© 1998 by Bobby Griggs.
// Program name: Square
// Purpose: To compute the square and square root of an integer.
// Info: Required program for Chapter 3
#include < iostream.h > // necessary for cout and cin
#include < stdio.h > // necessary for getchar
#include < iomanip.h > // necessary for ios settings
#include < math.h > // necessary for square root function
void main()
{
// define variable for entry by user
int number;
// set real number output as fixed
cout << setiosflags(ios::fixed);
cout << "Enter a positive integer ... ";
cin >> number;
// display 0 decimals for square of integer
cout << setprecision(0) << endl;
cout << "The square of the number is " << pow(number,2) << "!" << endl << endl;
// display 4 decimals for square root of integer
cout << setprecision(4);
cout << "The square root of the number is " << sqrt(number) << "!" << endl << endl;
// Prompt user to hit enter to continue
cout << "Hit enter to continue ... " << endl;
getchar();
}
|