计算一个数的开平方后值
来源:互联网 发布:需要淘宝店铺代运营的 编辑:程序博客网 时间:2024/05/16 06:27
不知道是不是自己大学时代本科的数值分析学的有点忘记了,不太记得计算开平方的算法了。在Points ON C 上看到这个算法,倍感亲切。
/*
** Compute the square root of a number.
*/
#include <stdio.h>
#include <stdlib.h>
int
main()
{
float new_guess;
float last_guess;
float number;
/*
** Prompt for and read the data, then check it.
*/
printf( "Enter a number: " );
scanf( "%f", &number );
if( number < 0 ){
printf( "Cannot compute the square root of a "
"negative number!/n" );
return EXIT_FAILURE;
}
/*
** Compute approximations to the square root until they
** don't change any more.
*/
new_guess = 1;
do {
last_guess = new_guess;
new_guess = ( last_guess + number / last_guess ) / 2;
printf( "%.15e/n", new_guess );
} while( new_guess != last_guess );
/*
** Print results.
*/
printf( "Square root of %g is %g/n", number, new_guess );
return EXIT_SUCCESS;
}
- 计算一个数的开平方后值
- python 计算开平方数
- 求一个数的开平方的倒数
- C/C++:输入一个数,输出这个数的绝对值,绝对值的正弦值,绝对值的开平方值。
- 开平方根的一个小函数
- 计算一个数的位数
- Acdream 1669 数一的偶像(大数开平方)
- 一个超级快速的开平方根C函数
- 开平方取倒数计算
- 一个计算完全数的算法
- 计算一个数是不是2的幂
- 计算一个数的平方Ex5
- 计算一个数的n次方
- 计算一个数的N次方
- 计算一个文件夹里的字符数
- 计算一个数阶乘的位数
- 计算一个数的各位之和
- 计算一个整数的各位数之和
- 字符的大小写转换
- 用C#实现基于TCP协议的网络通讯
- Brother-in-law embezzling sister wives
- sqlserver 的重装与登录失败而无法启动服务解决(错误1069)
- 听微软老员工讲述他们是如何走进微软的
- 计算一个数的开平方后值
- Log4j文档
- Her husband's sister is his love killer
- 大家来发现截取字符串的问题
- 有关UNICODE、ANSI字符集和相关字符串操作的总结
- 33条C#、.Net经典面试题目及答案
- 路径,文件,目录,I/O常见操作汇总(一)
- C#高级编程(第四版)中文版/C#高级编程(第三版)中文版电子书下载地址
- window.open()参数列表