在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 牛顿法计算根号下2的值 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 double a = 0, b = 2, t = 0; 14 while (b - a > 0.0000001) 15 { 16 t = (a + b) / 2; 17 if (t * t - 2 == 0) 18 { 19 Console.WriteLine(t); 20 break; 21 } 22 else if ((t * t - 2) > 0) 23 { 24 b = t; 25 Console.WriteLine(t * t - 2); 26 } 27 else 28 { 29 a = t; 30 Console.WriteLine(t * t - 2); 31 } 32 } 33 Console.WriteLine("sqt(2)={0}",t); 34 } 35 } 36 } http://www.51taoshi.com/ucenter/pub/diaryShow.action?did=140525134206646418 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论