Math Function Examples in C++


Example Program

Here is the simple program for math function Examples in C++.

Source Code Example : 1

#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
    int z=-10;
    cout<<"Absolute value of z=-10 : "<<abs(z)<<endl;
    return 0;
}
To download raw file Click Here

Output

Absolute value of z=-10 : 10

Source Code Example : 2

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    float x=-4.57;
    cout<<"\nAbsolute value of x=-4.57 is : "<<fabs(x)<<endl;
    return 0;
}
To download raw file Click Here

Output

Absolute value of x=-4.57 is : 4.57

Source Code Example : 3

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    float y=12.3;
    cout<<"\nCeiling value of y=12.3 : "<<ceil(y)<<endl;
    return 0;
}
To download raw file Click Here

Output

Ceiling value of y=12.3 : 13

Source Code Example : 4

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    float x=4.56;
    cout<<"Floor value of x=4.56 is : "<<floor(x)<<endl;
    return 0;
}
To download raw file Click Here

Output

Floor value of x=4.56 is : 4

Source Code Example : 5

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int x=3.0,y=4.0;
    cout<<"\nHypotenuse having other two sides as x=3.0 and"<<" y=4.0 : "<<hypot(x,y)<<endl;
    return 0;
}
To download raw file Click Here

Output

Hypotenuse having other two sides as x=3.0 and y=4.0 : 5

Source Code Example : 6

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    float y=100.0;
    cout<<"\nLog value of y=100.0 is : "<<log(y)<<endl;
    return 0;
}
To download raw file Click Here

Output

Log value of y=100.0 is : 4.60517

Source Code Example : 7

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int x=3.0,y=4.0;
    cout<<"\nPower value: x^y=(3.0^4.0) : "<<pow(x, y)<<endl;
    return 0;
}
To download raw file Click Here

Output

Power value: x^y=(3.0^4.0) : 81

Source Code Example : 8

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    double y=0.25;
    cout<<"Square root value of y=0.25 : "<<sqrt(y)<<endl;
    return 0;
}
To download raw file Click Here

Output

Square root value of y=0.25 : 0.5

Source Code Example : 9

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    double x=2.3;
    cout<<"\nSine value of x=2.3 : "<<sin(x)<<endl;
    cout<<"\nCosine value of x=2.3 : "<<cos(x)<<endl;
    cout<<"\nTangent value of x=2.3 : "<<tan(x)<<endl;
    x=1.0;
    cout<<"\nArc Cosine value of x=1.0 : "<<acos(x)<<endl;
    cout<<"\nArc Sine value of x=1.0 : "<<asin(x)<<endl;
    cout<<"\nArc Tangent value of x=1.0 : "<<atan(x)<<endl;
    x=57.3;
    cout<<"\nHyperbolic Cosine of x=57.3 : "<<cosh(x)<<endl;
    cout<<"\nHyperbolic tangent of x=57.3 : "<<tanh(x)<<endl;
    return 0;
}
To download raw file Click Here

Output

Sine value of x=2.3 : 0.745705

Cosine value of x=2.3 : -0.666276

Tangent value of x=2.3 : -1.11921

Arc Cosine value of x=1.0 : 0

Arc Sine value of x=1.0 : 1.5708Arc Tangent value of x=1.0 : 0.785398

Hyperbolic Cosine of x=57.3 : 3.83746e+24

Hyperbolic tangent of x=57.3 : 1


Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes