站长资讯网
最全最丰富的资讯网站

c语言开根号代码是什么

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

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; }

c语言开根号代码是什么

推荐教程:《C#》

赞(0)
分享到: 更多 (0)