What is sqrt in c programming?
sqrt in c is a mathematical function which is used to calculate square root of a given number.
This function is defined in math.h header file.
Prototype
double sqrt(double m);
Parameters
sqrt function takes double type value as input parameter.
Return value
sqrt function returns square root of a given number.
Example program for sqrt in c
#include<stdio.h>
#include<math.h>
int main()
{
printf("The square root of 5.0 is %lf \n",sqrt(5.0));
return 0;
}
While using gcc use below command to add math header.
gcc file_name.c -lm
Code explanation
The square root of a given number is found by calling sqrt function and result is printed on to the console.
Difference between sqrt and pow in c
sqrt function is used to calculate the square root of a given number. pow is used to calculate the power of a number raised to the base value.
sqrt function takes one argument. pow function takes two arguments.
Prototypes are as follows
double sqrt(double value1);
double pow(double value1,double value2);
sqrt( ) | pow( ) |
Used to calculate square root of a given number. | Used to calculate power of a number raised to the base value. |
double sqrt(double value1); | double pow(double value1,double value2); |
Difference between sqrt and exp in c
sqrt function is used to calculate the square root of a given number. exp function is used to calculate the exponential value of a given number.
Prototypes are as follows
double sqrt(double value1);
double exp(double value1);
sqrt( ) | exp( ) |
Used to calculate square root of a given number. | Used to calculate exponential value of a given number. |
double sqrt(double value1); | double exp(double value1); |
People also ask for
What is sqrt function in c?
sqrt function is used to calculate the square root of a given number. It is defined in math.h header file.