What is sqrt() in C?

The sqrt() function in C returns the square root of a number.

You must import the <math.h> library to use sqrt().

Syntax

double sqrt(double x)

Parameters

  • x: A floating point value, e.g., 4.0, 5.0, 20.6, etc.

Return value

sqrt() returns the square root of x.

Example

In the example below, we use the sqrt() function to find the square root of some numbers.

#include <stdio.h>
// include the math libarary so as to use sqrt() method
#include <math.h>
// main function
int main () {
// Print square root of some values
printf("Square root of %lg is %lg\n", 4.0, sqrt(4) );
printf("Square root of %lg is %lg\n", 16.0, sqrt(16.0) );
printf("Square root of %lg is %lg\n", 3.3, sqrt(3.3) );
return(0);
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources