5. ข้อความ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 5-3  การใช้วงวน do-while เพื่อหารากที่สองของ x
double x = 1;
while (true) {
  x = (x + a/x) / 2.0;
  if ((x*x-a) < 1e-5) break;
}

double x = 1; do { x = (x + a/x) / 2.0; } while ((x*x-a) >= 1e-5);
©2009 S.Prasitjutrakul