- 430 名前:デフォルトの名無しさん mailto:sage [2008/11/08(土) 11:36:00 ]
- >>428
そこまで計算式や判定法が分かってるなら、すぐに解けそうなものだけど。。。 #include <stdio.h> #include <math.h> int main(int argc, char *argv[]) { static const double e = 1.0e-10; double x0, x1, a; printf("平方根を求めたい数を入力してください: "); scanf("%lf", &a); printf("解を求めるための初期値を入力してください: "); scanf("%lf", &x0); x1 = (x0 + a/x0)*0.5; while (fabs(x1-x0) > e) { x0 = x1; x1 = (x0 + a/x0)*0.5; } printf("%f の平方根は %f です\n", a, x1); return 0; }
|

|