练习:用迭代法求x=√a。要求前后两次求出的x的差的绝对值小于10
发布时间:2021-05-20 09:46:20 所属栏目:大数据 来源: https://blog.csdn.net/summoxj
导读:#include stdio.h ?#include conio.h ?#include math.h ?int main(){ ? ?float a,x0,x1; ? ?printf("请输入数字:"); ? ?scanf("%f",a); ? ?x0=a/2; ? ?x1=(x0+a/x0); ? ?do{ ? ? ?x0=x1; ? ? ?x1=(x0+a/x0)/2; ? ?}while(fabs(x0-x1)=1e-5); ? ?printf("%5.2
#include <stdio.h>
?#include <conio.h> ?#include <math.h> ?int main(){ ? ?float a,x0,x1; ? ?printf("请输入数字:"); ? ?scanf("%f",&a); ? ?x0=a/2; ? ?x1=(x0+a/x0); ? ?do{ ? ? ?x0=x1; ? ? ?x1=(x0+a/x0)/2; ? ?}while(fabs(x0-x1)>=1e-5); ? ?printf("%5.2f的平方根为%8.5fn",a,x1); ? ?getch(); ? ?return 0; ?} (编辑:北几岛) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |