Funciones Pre-definidas

advertisement
Funciones Pre-definidas
Using Mathematical Library Functions
• Many programmer-defined functions in library
• Math functions accessed by including <cmath>
– Common routines such as square root and power
– Overloading accommodates integer and floating-point data
– Complex expressions allowed in arguments
– Example
• float eval = sqrt(pow( 3.8, 7.55));
• Output: 154.413
Table 4-6
Common C++ Mathematical Functions
Figure 4-7
Passing Data to the sqrt() Function
Table 4-7
Selected Function Examples
#include <iostream> // this line may be placed second instead of first
#include <cmath>
// this line may be placed first instead of second
using namespace std;
int main()
{
int height;
double time;
height = 800;
time = sqrt(2 * height / 32.2);
cout << "It will take " << time << " seconds to fall "
<< height << " feet.\n";
return 0;
}
• 3.0 * sqrt(165 – 13.71) / 5
Download