*******//Math.h Header file//********
syntax: #include <math.h>
The math. h header defines different mathematical functions. All the functions are available in math.h library takes double(datatype) as an argument and returns double(datatype) as the result.
math. h provides Trigonometric Functions, Exponential and Logarithmic Functions, Rounding and Absolute Value Functions, etc.....
Math.h uses double datatype as input and result.
//**1. sqrt
In C programming, you can calculate the square root of a number using the sqrt() function, which is part of the math.h library.
#include <stdio.h>
#include <math.h>
int main() {
double number, result;
printf("Enter a number: ");
scanf("%lf", &number);
result = sqrt(number);
printf("Square root of %.2lf is %.2lf\n", number, result);
return 0;
}
//**2. power
In C programming, you can calculate the power of a number using the pow() function, which is part of the math.h library.
#include <stdio.h>
#include <math.h>
int main() {
double base, exponent, result;
printf("Enter the base: ");
scanf("%lf", &base);
printf("Enter the exponent: ");
scanf("%lf", &exponent);
result = pow(base, exponent);
printf("%.2lf raised to the power %.2lf is %.2lf\n", base, exponent, result);
return 0;
}
//**3. floor
In C programming, you can use the floor() function from the math.h library to round a floating-point number down to the nearest integer.
#include <stdio.h>
#include <math.h>
int main() {
double number;
printf("Enter a number: ");
scanf("%lf", &number);
double result = floor(number);
printf("The floor of %.2lf is %.2lf\n", number, result);
return 0;
}
//**4. ceil
In C programming, you can use the ceil() function from the math.h library to round a floating-point number up to the nearest integer.
#include <stdio.h>
#include <math.h>
int main() {
double number;
printf("Enter a number: ");
scanf("%lf", &number);
double result = ceil(number);
printf("The ceiling of %.2lf is %.2lf\n", number, result);
return 0;
}
Read more:
1. Day 9 : Input and Output Functions Detailed view in c language.
2. Day 8 : Various tyes of Constant Variable Declaration in c lang.
3. Day 7 : Constant Variable and swapping in c language.
4. Day 6 : Operators and Arithmetic calculation in c language.
Post a Comment