C Programming Tutorial
C Programming allows us to perform mathematical operations through the functions defined in
C Math Functions
In the C Programming Language, the sqrt function returns the square root of x.
Syntax
The syntax for the sqrt function in the C Language is:
double sqrt(double x);
Parameters or Arguments
A value used when calculating the square root of x.
Returns
The sqrt function returns the square root of x. If x is negative, the sqrt function will return a domain error.
Required Header
In the C Language, the required header for the sqrt function is:
#include <math.h>
Applies To
In the C Language, the sqrt function can be used in the following versions:
- ANSI/ISO 9899-1990
sqrt Example
/* Example using sqrt by c programming */
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
/* Define temporary variables */
double value;
double result;
/* Assign the value we will find the sqrt of */
value = 25;
/* Calculate the square root of value */
result = sqrt(value);
/* Display the result of the calculation */
printf("The Square Root of %f is %f\n", value, result);
return 0;
}
When compiled and run, this application will output:
The Square Root of 25.000000 is 5.000000
