English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

Usage and Example of C Library Function sqrt()

C Standard Library - <math.h>

C Library Function double sqrt(double x) Returns x square root.

Declaration

Below is the declaration of the sqrt() function.

double sqrt(double x)

Parameter

  • x  -- Floating-point value.

Return Value

This function returns the square root of x.

Online Example

This example demonstrates the usage of the sqrt() function.

#include <stdio.h>
#include <math.h>
int main()
{
    printf("%lf's square root is %lf\n", 54.0, sqrt(54.0));
    printf("%lf's square root is %lf\n", 38.0, sqrt(38.0));
    printf("%lf's square root is %lf\n", 8.0, sqrt(8.0));
    return(0);
}

Let's compile and run the above program, which will produce the following result:

54The square root of .000000 is 7.348469
38The square root of .000000 is 6.164414
8The square root of .000000 is 2.828427

C Standard Library - <math.h>