注册 登录
编程论坛 C++教室

求解 为什么运行结果不对啊??

啦啦啦VL 发布于 2014-04-22 09:29, 450 次点击
#include<stdio.h>
#include<math.h>
int main()
{
  void big(float a,float b,float c);
  void equality(float a,float b,float c);
  void small(float a,float b,float c);
  float a,b,c,d;
  printf("请输入三个数:");
  scanf("%f,%f,%f",&a,&b,&c);
  d=b*b-4*a*c;
  if(d>0) big(a,b,c);
  if(d==0) equality(a,b,c);
  if(d<0) small(a,b,c);
  
}
void big(float a,float b,float c)
{
  float x1,x2;
  x1=(-b+sqrt(b*b-4*a*c))/(2*a);
  x2=(-b-sqrt(b*b-4*a*c))/(2*a);
  printf("方程的根:%6.2f或%6.2f\n",x1,x2);
}
void equality(float a,float b,float c)
{
  float x;
  x=-b/(2*a);
  printf("方程的根:%6.2f\n",x);
}
void small(float a,float b,float c)
{
  printf("无解\n");
}
4 回复
#2
rjsp2014-04-22 10:41
输入什么
实际输出什么
你期待输出什么
#3
鸥翔鱼游2014-04-23 13:00
非常精彩,欣赏支持好友佳作
#4
啦啦啦VL2014-04-23 21:32
回复 2 楼 rjsp
求方程ax2+bx+c=0的根,输入abc的值  调用d >  ,< ,=0时的函数求解
#5
创世写生2015-04-06 11:56
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    double a,b,c;
    double delta,x1,x2;
    int sign,stop;
    cout<<"请输入3个系数a(a!=0),b,c"<<endl;
    cin>>a>>b>>c;
    delta=b*b-4*a*c;
    if(a==0)
    {
        cout<<"a不能等于0,不是一元二次方程"<<endl;
    }
    else
    {
        if(delta==0)
        {
            cout<<"方程有两个实根:x1=x2="<<-b/(2*a)<<endl;
        }
        else
        {
            if(delta>0)
                sign=1;
            else
                sign=0;
            delta=sqrt(fabs(delta));
            x1=-b/(2*a);
            x2=delta/(2*a);
            if(sign){
                cout<<"方程有两个不同的实根:x1="<<x1+x2<<"  "<<"x2="<<x1-x2<<endl;
            }
            else{
                cout<<"方程无实根,有两个不同的复数根:x1="<<x1<<"+i"<<"  "<<x2<<"x2="<<x1<<"-i"<<x2<<endl;
            }
        }
    }
}
1