Mathematical Functions in C++ and Source Code
Mathematical Functions in C++ and Source Code
cos
sin
tan
acos
asin
atan
Compute
Compute
Compute
Compute
Compute
Compute
cosine (function )
sine (function )
tangent (function )
arc cosine (function )
arc sine (function )
arc tangent (function )
Hyperbolic functions
cosh
sinh
tanh
acosh
asinh
atanh
Compute
Compute
Compute
Compute
Compute
Compute
Compute
Compute
Compute
Compute
pow
sqrt
cbrt
hypot
These handouts are in no way a substitute of recommended textbooks and lectures delivered in the computer
laboratory of BSRS department.
Compute
Compute
Compute
Compute
ceil
floor
fmod
trunc
round
lround
llround
rint
lrint
llrint
nearbyint
remainder
remquo
fdim
fmax
fmin
fabs
abs
Note: Given above is not a complete list of mathematical functions offered by C++. I have
included only those which are, however, required to design source codes of the topics taught in
the subject of Numerical Analysis and Computer applications. Detailed explanation and use of
the above functions has been discussed with you in the computer laboratory of BSRS department
by me while using the IDE of Dev C++. You must google to find rest of the functions.
2
Sania Qureshi
Lecturer of Mathematics
Department of BSRS
Mehran, UET, Jamshoro.
These handouts are in no way a substitute of recommended textbooks and lectures delivered in the computer
laboratory of BSRS department.
Source Code 01
// This program computes absolute, relative and percentile errors
// Exact Value = 74.892456 and Approximate Value (up to 3dp)= 74.892
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
float exact_value,approximate_value,absolute_error,relative_error,percentile_error;
cout<<"Enter Exact and Approximate Value = ";
cin>>exact_value>>approximate_value;
absolute_error=abs(exact_value-approximate_value);
relative_error=absolute_error/abs(exact_value);
percentile_error=relative_error*100;
cout<<"\n Absolute Error is = "<<absolute_error<<endl;
cout<<"\n Relative Error is
= "<<relative_error<<endl;
cout<<"\n Percentile Error is = "<<percentile_error<<endl;
system("pause");
return 0;
}
Output:
Enter Exact and Approximate Value = 74.892456
Absolute Error is
= 0.000457764
Relative Error is
= 6.11228e-006
3
Sania Qureshi
Lecturer of Mathematics
Department of BSRS
Mehran, UET, Jamshoro.
74.892