負數,不可以拿來開根號
(高顯忠, sjgau4311@gmail.com, 2011-02-08 08:24)
1樓
#if 0
// sqrt(-3)= -1.#IND00,
負數,不可以拿來開根號
i= -3, i*i= 9, sqrt(i)= -1.#IND00
// no good!
i= -2, i*i= 4, sqrt(i)= -1.#IND00
i= -1, i*i= 1, sqrt(i)= -1.#IND00
i= 0, i*i= 0, sqrt(i)= 0.000000
// OK
i= 1, i*i= 1, sqrt(i)= 1.000000
i= 2, i*i= 4, sqrt(i)= 1.414214
i= 3, i*i= 9, sqrt(i)= 1.732051
i= 4, i*i= 16, sqrt(i)= 2.000000
i= 5, i*i= 25, sqrt(i)= 2.236068
i= 6, i*i= 36, sqrt(i)= 2.449490
i= 7, i*i= 49, sqrt(i)= 2.645751
i= 8, i*i= 64, sqrt(i)= 2.828427
i= 9, i*i= 81, sqrt(i)= 3.000000
i= 10, i*i= 100, sqrt(i)= 3.162278
i= 11, i*i= 121, sqrt(i)= 3.316625
i= 12, i*i= 144, sqrt(i)= 3.464102
i= 13, i*i= 169, sqrt(i)= 3.605551
i= 14, i*i= 196, sqrt(i)= 3.741657
i= 15, i*i= 225, sqrt(i)= 3.872983
i= 16, i*i= 256, sqrt(i)= 4.000000
i= 17, i*i= 289, sqrt(i)= 4.123106
i= 18, i*i= 324, sqrt(i)= 4.242641
i= 19, i*i= 361, sqrt(i)= 4.358899
i= 20, i*i= 400, sqrt(i)= 4.472136
i= 21, i*i= 441, sqrt(i)= 4.582576
i= 22, i*i= 484, sqrt(i)= 4.690416
i= 23, i*i= 529, sqrt(i)= 4.795832
Press any key to continue
#endif
// ----------------------------------------------
#include <stdio.h>
#include <math.h>
// ----------------------------------------------
// for skip(), pause()
int main()
{
int i;
for (i=-3;i<=23;i++) {
printf("i= %5d, i*i= %5d, sqrt(i)= %10.6lf\n", i, i*i, sqrt(i));
}
return(0);
}