Tuesday, March 31, 2015

Commonly used Math functions

Script

#include <iostream>
using namespace std;
#include <cmath>

int main()
{
        double rampit;
        rampit = pow(25,3);
        cout << "25 to the power of 3 is: " << rampit << endl;

        double squary;
        squary = sqrt(169.0);
        cout << "The square root of 169.0 is: " << squary << endl;

        double cuby;
        cuby = cbrt(216.57);
        cout << "The cube root of 216.57 is: " << cuby << endl;

        double hype;
        hype = hypot(10,15);
        cout << "The hypotenuse of a triangle with sides 10 and 15 is: " << hype << endl;

        return 0;
}


Execution

25 to the power of 3 is: 15625
The square root of 169.0 is: 13
The cube root of 216.57 is: 6.00527
The hypotenuse of a triangle with sides 10 and 15 is: 18.0278

No comments:

Post a Comment