高手 查一下C++2008 二分法求零点 的问题

[复制链接]
查看11 | 回复3 | 2009-3-31 21:06:26 | 显示全部楼层 |阅读模式
这里是自己从网上找的,有点改变的程序,
运行后有问题呀
#include
#include
#include
#define null 0
double fx(double);//fx函数
void main()
{
double xa(null),xb(null),xc(null);
do
{
printf("请输入一个范围x0 x1:");
std::cin>>xa>>xb; //输入xa xb的值
printf("%f %f",xa,xb);
}
while(fx(xa)*fx(xb)>=0);//判断输入范围内是否包含函数值0
do
{
if(fx((xc=(xa+xb)/2))*fx(xb)1e-5||fx(xc)------ 已启动生成: 项目: 数学建模, 配置: Debug Win32 ------
1>正在编译...
1>二分法求零点.cpp
1>d:\study\数学建模\数学建模\二分法求零点.cpp(32) : error C2146: 语法错误 : 缺少“;”(在标识符“fx”的前面)
1>d:\study\数学建模\数学建模\二分法求零点.cpp(32) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\study\数学建模\数学建模\二分法求零点.cpp(33) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\study\数学建模\数学建模\二分法求零点.cpp(33) : error C2556: “int fx(double)”: 重载函数与“double fx(double)”只是在返回类型上不同
1>
d:\study\数学建模\数学建模\二分法求零点.cpp(5) : 参见“fx”的声明
1>d:\study\数学建模\数学建模\二分法求零点.cpp(33) : error C2371: “fx”: 重定义;不同的基类型
1>
d:\study\数学建模\数学建模\二分法求零点.cpp(5) : 参见“fx”的声明
1>生成日志保存在“file://d:\study\数学建模\数学建模\Debug\BuildLog.htm”
1>数学建模 - 5 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
请高手解决啊!分少希望不要介意啊!谢谢啦

回复

使用道具 举报

千问 | 2009-3-31 21:06:26 | 显示全部楼层
#include #include#include#define null 0 double fx(double x) { return(2.0*pow(x,3)-4.0*pow(x,2)+3.0*x-6.0); } void main() { double xa(null),xb(null),xc(null); do {
printf("请输入一个范围x0 x1:");
std::cin>>xa>>xb; //输入xa xb的值
printf("%f %f",xa,xb); } whil...
回复

使用道具 举报

千问 | 2009-3-31 21:06:26 | 显示全部楼层
//欢迎在线讨论#include #include#include#define null 0 double fx(double x) {return(2.0*pow(x,3)-4.0*pow(x,2)+3.0*x-6.0); } void mai...
回复

使用道具 举报

千问 | 2009-3-31 21:06:26 | 显示全部楼层
dobule fx(double x) //就double 写错了而已{ return(2.0*pow(x,3)-4.0*pow(x,2)+3.0*x-6.0); }...
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行