C sqrt 函数

C sqrt 函数是 Math Functions 之一,用于查找数字或指定表达式的平方根。此语言中 sqrt 的语法如下所示。

double sqrt(double number);

C sqrt 函数示例

math sqrt 函数允许您查找给定数字的平方根。在此程序中,我们将查找平方根并显示输出。

#include <stdio.h>
#include <math.h>

int main()
{
    printf("\n The Square Root Value of 0       = %.4f ", sqrt(0));
    printf("\n The Square Root Value of 1       = %.4f ", sqrt(1));
    
    printf("\n The Square Root Value of 125     = %.4f ", sqrt(125));
    printf("\n The Square Root Value of 500.36  = %.4f ", sqrt(500.36));
    
    printf("\n The Square Root Value of -27.32  = %.4f ", sqrt(-27.32));  
    printf("\n The Square Root Value of -90     = %.4f ", sqrt(-90));
  
    return 0;
}
sqrt function to find the square root Example

C 平方根示例 2

在此 C 编程 示例中,我们允许用户输入自己的值。接下来,此 程序 使用 math sqrt 函数来查找用户给定数字的平方根。

#include <stdio.h>
#include <math.h>

int main()
{
    float number, sqrtValue;

    printf(" Please Enter any Numeric :  ");
    scanf("%f", &number);
  
    sqrtValue = sqrt(number);
  
    printf("\n The Square Root of %.2f = %.4f ", number, sqrtValue);
  
    return 0;
}
 Please Enter any Numeric :  64

 The Square Root of 64.00 = 8.0000