一分钟学会sqrt()函数,如何求平方根
使用前需要引入#include<math.h>
使用时sqrt()函数的输入量需要时float类型的变量(不一定要double)
eg
#include<math.h>
#include<stdio.h>
float x,y;
scanf("%d",&x)
y=sqrt(x)
随后即可,这里带上一道浙大练习题的使用sqrt函数的方法作为例子
#include<stdio.h>
int main()
{
float x,y;
scanf("%f", &x);
if (x != 0)
{
y = 1 / x;
}
else
{
y = 0;
}
printf(“f(%.1f) = %.1f”,x,y);
return 0;
}