声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1830|回复: 1

[C/C++] 帮忙改个程序,运行不出来,谢谢啦

[复制链接]
发表于 2012-5-14 10:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
#include <stdio.h>
#include <math.h>
#define e 0.00001
#define tt 0.5
double f(double x)
{ double y=sin(x);
  return(y);
}
finding(double *p1,double *p2)
{ double x1=4,x2,x3,t,f1,f2,f3,h=tt;
  int n=0;
  x2=x1+h;f1=f(x1);f2=f(x2);
  if (f2>f1) {h=-h;t=x2;x2=x1;x1=t;}
  do
  {  x3=x2+h;h=2*h;f3=f(x3);n=n+1;}
     while(f3<f2);
    if(x1>x3) {t=x1;x1=x3;x3=t;}
    *p1=x1;*p2=x3;
    n=n+1;
    return(n);
}
double twice(double *p)
{ double
  a,b,x1,x2,f1,f2,x3,c1,c2,f3,x4,f4;
  int n=0;
  finding(&a,&b);
  x1=a;x3=b;
  do
  { x2=(x1+x3)/2;
    f1=f(x1);f2=f(x2);n=n+1;f3=f(x3);
    c1=(f3-f1)/(x3-x1);
    c2=(((f2-f1)/(x2-x1))-c1)/(x2-x3);
    x4=(x1+x3-c1)/c2/2;
    f4=f(x4);
    n=n+1;
    if (x4>x2)
                if (f2>=f4)
                {x1=x2;x2=x4;
                else
                        x3=x4;
                }
                else if (f2>=f4) {x3=x2;x2=x4;else x1=x4;}
  }
  while (fabs((f2-f4)/f2)<e);
  *p=x2;
  return(n);
}
void main()
{ double a,b,x,min,n1,n2;
  n1=finding(&a,&b);
  n2=twice(&x);
  min=f(x);
  printf("\n The area is %f to %f.",a,b);
  printf("\n The min is %f and the result is %f.",x,min);
}
回复
分享到:

使用道具 举报

发表于 2012-5-30 08:32 | 显示全部楼层
帮你顶一下。。。。。。  

点评

灌水??  发表于 2012-5-31 01:04
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-11 21:58 , Processed in 0.064316 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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