/*
C/C++の宿題片付けます 161代目
http://t...content-available-to-author-only...h.net/test/read.cgi/tech/1354070278/
125 名前:デフォルトの名無しさん [sage]: 2012/12/06(木) 10:12:21.78
[1] 授業単元:c言語 関数&配列
[2] 問題文 関数配列の問題です。
http://www.dotup.org/uploda/www.dotup.org3703015.pdf
[3] 環境
[3.1] OS: Linux
[3.2] コンパイラ名とバージョン: gcc
[3.3] 言語: C
[4] 期限:12/11
ポインターは使わずによろしくお願いいたします
1. 与えられた数xの3乗根を返す関数cube_root(x)とこれを呼び出して1から10までの3乗根の値を表示する
プログラムを作成せよ。
*/
#include<stdio.h>
double cube_root(double d)
{
double dmin = 1.0;
double dmax = d;
double tmp, sanjo;
while (1) {
// 中間値
tmp = (dmin + dmax) / 2.0;
// tmp が dmax, dmin どちらかにくっついてしまったら、計算はここまで
if (tmp == dmin || tmp == dmax) {
break;
}
// 実際に3乗したのを判定して狭める
sanjo = tmp * tmp * tmp;
if (sanjo < d) {
dmin = tmp;
} else if (sanjo > d) {
dmax = tmp;
} else {
break; // ジャスト
}
}
return tmp;
}
int main()
{
double a;
for (a = 1.0; a <= 10.0; a += 1.0) {
printf("%2.0fの3乗根 = %.10f\n", a
, cube_root
(a
)); }
return 0;
}
LyoKICAgIEMvQysr44Gu5a6/6aGM54mH5LuY44GR44G+44GZIDE2MeS7o+ebrgogICAgaHR0cDovL3QuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmgubmV0L3Rlc3QvcmVhZC5jZ2kvdGVjaC8xMzU0MDcwMjc4LwogICAgICAgIDEyNSDlkI3liY3vvJrjg4fjg5Xjgqnjg6vjg4jjga7lkI3nhKHjgZfjgZXjgpMgW3NhZ2Vd77yaIDIwMTIvMTIvMDYo5pyoKSAxMDoxMjoyMS43OCAgCiAgICAgICAgWzFdIOaOiOalreWNmOWFg++8mmPoqIDoqp4g6Zai5pWw77yG6YWN5YiXCiAgICAgICAgWzJdIOWVj+mhjOaWh+OAgOmWouaVsOmFjeWIl+OBruWVj+mhjOOBp+OBmeOAggogICAgICAgIO+9iO+9lO+9lO+9kO+8mi8vd3d3LmRvdHVwLm9yZy91cGxvZGEvd3d3LmRvdHVwLm9yZzM3MDMwMTUucGRmCiAgICAgICAgWzNdIOeSsOWigyAKICAgICAgICDjgIBbMy4xXSBPU++8miBMaW51eCAKICAgICAgICDjgIBbMy4yXSDjgrPjg7Pjg5HjgqTjg6nlkI3jgajjg5Djg7zjgrjjg6fjg7PvvJogZ2NjIAogICAgICAgIOOAgFszLjNdIOiogOiqnu+8miBDIAogICAgICAgIFs0XSDmnJ/pmZA6MTIvMTEgCiAgICAgICAg44Od44Kk44Oz44K/44O844Gv5L2/44KP44Ga44Gr44KI44KN44GX44GP44GK6aGY44GE44GE44Gf44GX44G+44GZIAogICAgMS4g5LiO44GI44KJ44KM44Gf5pWweOOBrjPkuZfmoLnjgpLov5TjgZnplqLmlbBjdWJlX3Jvb3QoeCnjgajjgZPjgozjgpLlkbzjgbPlh7rjgZfjgaYx44GL44KJMTDjgb7jgafjga4z5LmX5qC544Gu5YCk44KS6KGo56S644GZ44KLCiAgICAgICDjg5fjg63jgrDjg6njg6DjgpLkvZzmiJDjgZvjgojjgIIKKi8KI2luY2x1ZGU8c3RkaW8uaD4KCmRvdWJsZSBjdWJlX3Jvb3QoZG91YmxlIGQpCnsKICAgIGRvdWJsZSBkbWluID0gMS4wOwogICAgZG91YmxlIGRtYXggPSBkOwogICAgZG91YmxlIHRtcCwgc2Fuam87CgogICAgd2hpbGUgKDEpIHsKICAgICAgICAvLyDkuK3plpPlgKQKICAgICAgICB0bXAgPSAoZG1pbiArIGRtYXgpIC8gMi4wOwogICAgICAgIC8vIHRtcCDjgYwgZG1heCwgZG1pbiDjganjgaHjgonjgYvjgavjgY/jgaPjgaTjgYTjgabjgZfjgb7jgaPjgZ/jgonjgIHoqIjnrpfjga/jgZPjgZPjgb7jgacKICAgICAgICBpZiAodG1wID09IGRtaW4gfHwgdG1wID09IGRtYXgpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIC8vIOWun+mam+OBqzPkuZfjgZfjgZ/jga7jgpLliKTlrprjgZfjgabni63jgoHjgosKICAgICAgICBzYW5qbyA9IHRtcCAqIHRtcCAqIHRtcDsKICAgICAgICBpZiAoc2Fuam8gPCBkKSB7CiAgICAgICAgICAgIGRtaW4gPSB0bXA7CiAgICAgICAgfSBlbHNlIGlmIChzYW5qbyA+IGQpIHsKICAgICAgICAgICAgZG1heCA9IHRtcDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBicmVhazsgICAgICAgICAgICAgIC8vIOOCuOODo+OCueODiAogICAgICAgIH0KICAgIH0KICAgIHJldHVybiB0bXA7Cn0KCmludCBtYWluKCkKewogICAgZG91YmxlIGE7CiAgICBmb3IgKGEgPSAxLjA7IGEgPD0gMTAuMDsgYSArPSAxLjApIHsKICAgICAgICBwcmludGYoIiUyLjBm44GuM+S5l+aguSA9ICUuMTBmXG4iLCBhLCBjdWJlX3Jvb3QoYSkpOwogICAgfQogICAgcmV0dXJuIDA7Cn0=