c语言解方程.docVIP

  • 86
  • 0
  • 约1.56千字
  • 约 3页
  • 2018-03-14 发布于河南
  • 举报
c语言解方程

 一、迭代法求方程根   /* 迭代法求一个数的平方根 */   #define Epsilon 1.0E-6 /*控制解的精度*/   #includemath.h   main()   {   float a,x0,x1;   printf(请输入要求的数:);   scanf(%f,a);   x0=a/2;   x1=(x0+a/x0)/2;   while(fabs(x1-x0)=Epsilon)     {     x0=x1;     x1=(x0+a/x0)/2;     }   printf(%f的平方根:%f.5\n,x1);   }   二、求方程根的另一种算法   #define Epsilon 1.0E-6 /*控制解的精度*/   #include stdio.h   #include math.h   main()   {   float num,pre,this;   do     {     scanf(%f,num);/*输入要求平方根的数*/     }while(num0);   if (num==0)     printf(the root is 0);   else   {    this=1;    do    {     pre=this;     this=(pre+num/pre)/2;   

文档评论(0)

1亿VIP精品文档

相关文档