【发布时间】:2021-04-21 00:33:39
【问题描述】:
我正在尝试将参数输入到平方根函数中。该函数将接受 b 乘以 b 的值,但它不接受 b 乘以 b 减 4 的值。这是为什么呢?我怎样才能绕过这个?提前致谢。
#include <stdio.h>
//Function to compute square root of a number
float squareRoot (float x)
{
float guess = 1.0;
while (( x/ (guess * guess)) != 1)
{
guess = (x/ guess + guess) / 2.0;
}
return guess;
}
int main (void)
{
float b;
float valueOne;
float answerOne;
float squareRoot (float x);
printf("give me a 'b'\n");
scanf("%f", &b);
valueOne = b*b-4;
answerOne = squareRoot(valueOne);
printf("%f", answerOne);
return 0;
}
【问题讨论】: