c++程序简单问题。。。。。。。

#include
#include
using namespace std;
int flag(double (*f)(double),double l,double r,double &root)
{
int flag;double m;
if(f(l)*f(r)>0)
{
flag=0;
}
else
{
while(fabs(l-r)>1e-5)
{
m=(l+r)/2;
if(f(l)*f(m)<=0) r=m;
else l=m;
}
flag=1;
}
return flag;
root=m;
}
void main()
{
double root;
if(flag(sin,1,4,root)>0) cout<<root<<endl;
else cout<<"no root"<<endl;
system("pause");
}
为什么结果不对啊???图片

附源程序图,,,,,,,,,,,,:图片

#include
#include
using namespace std;
int flag(double (*f)(double),double l,double r,double &root)
{
int flag;double m;
if(f(l)*f(r)>0)
{
flag=0;
}
else
{
while(fabs(l-r)>1e-5)
{
m=(l+r)/2;
if(f(l)*f(m)<=0) r=m;
else l=m;
}
flag=1;
}
return flag;
root=m;
}
void main()
{
double root;
if(flag(sin,1,4,root)>0) cout<<root<<endl;
else cout<<"no root"<<endl;
system("pause");
}

return flag;
root=m;
换一下位置,先赋值再return
root=m;
return flag;