首页 > Windows开发 > 详细

c#用牛顿法计算根号下2的值

时间:2016-09-22 00:59:45      阅读:249      评论:0      收藏:0      [点我收藏+]
 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

c#用牛顿法计算根号下2的值

原文:http://www.cnblogs.com/zhubinglong/p/5894497.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!