标题:一个求根的程序,搞不定啊!
取消只看楼主
birdfling
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2006-4-1
 问题点数:0 回复次数:0 
一个求根的程序,搞不定啊!

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
float res(int,int,int);
float main()
{
int A,B,C;
cout<<"请输入A,B,C的值:"<<endl;
cin>>A>>B>>C;
float x,y;
if(A<0)
{
if(B*B-4*(-A)*(-C)>0)
{
x=(B+sqrt(B*B-4*(-A)*(-C)))/(2*A);
y=(B-sqrt(B*B-4*(-A)*(-C)))/(2*A);
cout<<"方程的两个根x,y为:"<<" x="<<setiosflags(ios::fixed)<<setprecision(3)<<x<<" y="<<setiosflags(ios::fixed)<<setprecision(3)<<y<<endl;
}
else if(B*B-4*(-A)*(-C)==0)
{
x=B/(2*A);
y=x;
cout<<"方程的两个根x,y为:"<<" x=y="<<setiosflags(ios::fixed)<<setprecision(3)<<y<<endl;
}
else cout<<"此方程无根!"<<endl;
}
else if(A=0)
{
x=-(C/B);
y=x;
}
else
{
if(B*B-4*A*C>0)
{
x=((-B)+sqrt(B*B-4*A*C))/(2*A);
y=((-B)-sqrt(B*B-4*A*C))/(2*A);
cout<<"方程的两个根x,y为:"<<" x="<<setiosflags(ios::fixed)<<setprecision(3)<<x<<" y="<<setiosflags(ios::fixed)<<setprecision(3)<<y<<endl;
}
else if(B*B-4*A*C==0)
{
x=B/(2*A);
y=x;
cout<<"方程的两个根x,y为:"<<" x=y="<<setiosflags(ios::fixed)<<setprecision(3)<<y<<endl;
}
else cout<<"此方程无根!"<<endl;
}
return 0;
}

编译没错,可是结果不对,不知道怎么改了啊。

搜索更多相关主题的帖子: include 
2006-04-06 13:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-55521-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.907549 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved