Sure! In C language, the math.h library provides many mathematical functions for performing various mathematical operations. Here's a simple explanation with an example:
Let's say you want to calculate the square root of a number. You can use the sqrt()
function from the math.h
library.
#include <stdio.h>
#include <math.h>
int main() {
double number, squareRoot;
printf("Enter a number: ");
scanf("%lf", &number);
// Calculate square root using sqrt() function
squareRoot = sqrt(number);
printf("Square root of %.2lf = %.2lf\n", number, squareRoot);
return 0;
}
In this example
stdio.h
and math.h
header files to use the standard input/output functions and mathematical functions respectively.number
to store the input number and squareRoot
to store the calculated square root.printf
and read it using scanf
.sqrt()
function from the math.h
library.printf
.When you run this program, it will prompt you to enter a number, calculate its square root using the sqrt()
function, and then print the result.