1 条题解

  • 0
    @ 2025-4-12 22:03:05

    C :

    #include<stdio.h>
    #include<math.h>
    int main()
    {
    	double a, x2, x1;
    	scanf("%lf", &a);
    	x2 = 1.0;
    	do
    	{
    		x1 = x2;
    		x2 = 0.5 * (x1 + a / x1);
    	}
    	while(fabs(x1 - x2) >= 1e-5);
    	printf("%.3lf\n", x2);
    	return 0;
    }
    

    C++ :

    #include<iostream>
    #include<stdio.h>
    #include<math.h>
    using namespace std;
    int main()
    {
     double x1,x2,a;
    cin>>a;
     if(a>=0)
     { 
      x2=1.0;
      do
      {
       x1=x2;
       x2=0.5*(x1+a/x1);
      }
      while(fabs(x2-x1)>=1e-5);
      printf("%.3f\n",x2);
     }
     return 0;
    }
    

    Pascal :

    var s:longint;
    begin
      readln(s);
      writeln(sqrt(s):0:3);
    end.
    
    • 1

    C语言程序设计教程(第三版)课后习题6.11

    信息

    ID
    2708
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者