有戏

 找回密码
 立即注册
简历下载
搜索
热搜: 活动 交友 discuz
查看: 873|回复: 0

用牛顿迭代法求根号n

[复制链接]

57

主题

63

帖子

1万

积分

论坛元老

Rank: 8Rank: 8

积分
17917
发表于 2015-1-22 10:01:45 | 显示全部楼层 |阅读模式
#include<stdio.h>
#include<math.h>
#define JD 1e-6

main()
  {
    float   n,x1,x2;
    printf("请输入要求根号的数n =  ");
    scanf("%f",&n);
    x2=n;
    while(fabs(x1-x2)>=JD)
    {
        x1=x2;
        x2=(x1+n/x1)/2;
    }

    printf("结果等于%8.5f\n",x1);
     return 0;
}
大家好
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|有戏 粤ICP备2020111303号

GMT+8, 2025-12-6 14:45 , Processed in 0.077023 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表