.
3ss.cn

c语言开根号代码是什样

在C语言中,开根号的代码是“sqrt(浮点值x)”;例如“sqrt(4.0)”,对4进行平方根运算,结果为2。sqrt()是c语言内置的开根号运算函数,其运算结果是函数变量的算术平方根;该函数既不能运算负数值,也不能输出虚数结果。

本教程操作环境:windows7系统、C++17版本、Dell G3电脑。

在头文件中加入#include<math.h>

之后使用sqrt即可,可以用double定义

举个例子:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
double sqrt(double n);
int main(void)
{
double x = 3.1415926540, result;
result = sqrt(x);
printf("The square root of %lf is %lf", x, result);
return 0;
}

赞(0)
未经允许不得转载:互联学术 » c语言开根号代码是什样

评论 抢沙发