C语言中开平方函数是什么?

如题所述

1、C语言中求平方根的函数是sqrt
2、实例:
函数原型: double sqrt(double x);和 float sqrt(float x);
头文件:#include <math.h>
参数说明:x 为要计算平方根的值
返回值:返回 x 平方根
注意事项:如果 x < 0,将会导致 domain error 错误。
示例计算200 的平方根值:
#include <math.h>
#include <stdio.h>
int main(){
double root;
root = sqrt(200);
printf("answer is %f\n", root);
return 0;
}

//输出:answer is 14.142136
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-09-24
开平方函数是Sqrt()
例如 int i,j;
i=Sqrt(j);
i为j的算数平方根
用sqrt()函数要有头函数“math.h"
第2个回答  2010-04-02
写错了吧,是sqrt,不是sprt
另外,q s是宏定义,使用时最好用()把它们括起来
改为
double x1, x2;
x1 = (q) + sqrt( (double)(s) ) / 2*a;
第3个回答  2013-11-18
函数原型:double sqrt(double);
头文件为<math.h>
Linux 中使用gcc编译器 需要加 -lm 作为链接,调用数学函数库math.h
第4个回答  2012-10-15
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
double x,x1,x2,p=b*b-4*a*c,s=sqrt(p);
if(a==0) {x=(double)-c/b;printf("x=%f\n",x);}
else if(p>=0) {x1=(-b+s)/(2*a);
x2=(-b-s)/(2*a);
printf("p=%.2f,s=%.2f,x1=%.2f, x2=%.2f\n",p,s,x1,x2);}
else {printf("p=%f,s=%f\n 方程没有实数根。\n",p,s);}
}
相似回答