03 Mathematical Function
03 Mathematical Function
Mathematical Functions
C sqrt(x)
pow(x,y)
ceil(x)
floor(x)
round(x)
abs(a)
max(a,b)
min(a,b)
sin(x)
cos(x)
tan(x)
By:
Dr. P.S. Tanwar
Mathematical Functions
C sqrt(x) • square root
pow(x,y) • x raised to power y
ceil(x) • ceiling value of x
floor(x) • floor value of x
round(x) • round value of x
abs(a) • absolute value of a
max(a,b) • Maximum of a and b
min(a,b) • minimum of a and b
sin(x) • sin value of x
cos(x) • cos value of x
tan(x) • tan value of x
By:
Dr. P.S. Tanwar
Mathematical Functions
In C
Syntax
double sqrt(double x)
Work
This function will return square root of x
Ex:
double x=16.0,y; x y
y=sqrt(16.0);
16.0 4.0
By:
Dr. P.S. Tanwar
Mathematical Functions
In C
Syntax
double pow(double x,double y)
Work
Ex:
x y z
double x=2.0,y=3.0,z;
2.0 3.0 8.0
z=pow(x,y);
By:
Dr. P.S. Tanwar
Mathematical Functions
In C
Output
Syntax 3
3
int ceil(double x) 3
Work
This function will return rounding up value.
Ex:
printf(“%d\n%d\n%d”,ceil(2.2),ceil(2.5),ceil(2.7));
By:
Dr. P.S. Tanwar
Mathematical Functions
In C
Output
Syntax 2
2
int floor(double x) 2
Work
This function will return rounding down value.
Ex:
printf(“%d\n%d\n %d”,floor(2.2),floor(2.5),floor(2.7));
By:
Dr. P.S. Tanwar
Mathematical Functions
In C
Output
Syntax 2
3
round(double x) 3
Work
This function will return rounding value.
Ex:
printf(“%d\n%d\n %d”,round(2.2),round(2.5),round(2.7));
By:
Dr. P.S. Tanwar
Mathematical Functions
C Syntax
abs(double x)
Work
This function will return absolute value(only +ve values).
Ex:
Output
printf(“%f\n”,abs(2.2)); 2.200000
2.200000
printf(“%f\n”, abs(-2.2));
By:
Dr. P.S. Tanwar
Mathematical Functions
C Syntax
double min(double x, double y)
Work
This function will return minimum value from both of the
arguments
Output
Ex:
2
printf(“%d\n”,min(2,3));
By:
Dr. P.S. Tanwar
Mathematical Functions
C Syntax
double max(double x, double y)
Work
This function will return maximum value from both of the
arguments
Output
Ex:
3
printf(“%d\n”,max(2,3));
By:
Dr. P.S. Tanwar
Mathematical Functions
C Syntax
double sin(double angle)
Work
This function will return sin value of given angle.
Ex:
Output
printf(“%f\n”,sin(0)); 0.000000
By:
Dr. P.S. Tanwar
Mathematical Functions
C Syntax
double cos(double angle)
Work
This function will return cosine value of given angle.
Ex:
Output
printf(“%f\n”,cos(0)); 1.000000
By:
Dr. P.S. Tanwar
Mathematical Functions
C Syntax
double tan(double angle)
Work
This function will return tan value of given angle.
Ex:
Output
printf(“%f\n”,tan(0)); 0.000000
By:
Dr. P.S. Tanwar