| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1704 人关注过本帖
标题:一元二次方程的问题
取消只看楼主 加入收藏
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
结帖率:91.43%
收藏
已结贴  问题点数:20 回复次数:4 
一元二次方程的问题
通过一元二次方程如何求出它的根呢?
我做出的是:
#include "math.h"
double main()
{
    do
    {
    double a,b,c,d,x,x1,x2;
    cout<<"请输入一元二次方程的a、b、c"<<endl;
    cin>>a>>b>>c;
    d=b*b-4*a*c;
    if(d<0)
    {
        cout<<"此方程无解"<<endl;
    }
    }while(d>=0)
    {
        if(d==0)
        {
            x=b/2/a;
            cout<<"x1=x2=-"<<x<<endl;
        }
        else
        {
            x1=b/2/a+sqrt(b*b-4*a*c)/2/a;
            x2=b/2/a-sqrt(b*b-4*a*c)/2/a;
            cout<<"x1=-"<<x1<<";"<<"x2=-"<<x2<<endl;
        }
    }
    return 0;
}
可下面显示错误的好多
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
F:\教育教学\练习\1.cpp(7) : error C2065: 'cout' : undeclared identifier
F:\教育教学\练习\1.cpp(7) : error C2297: '<<' : illegal, right operand has type 'char [28]'
F:\教育教学\练习\1.cpp(7) : error C2065: 'endl' : undeclared identifier
F:\教育教学\练习\1.cpp(8) : error C2065: 'cin' : undeclared identifier
F:\教育教学\练习\1.cpp(8) : error C2296: '>>' : illegal, left operand has type 'double'
F:\教育教学\练习\1.cpp(8) : error C2297: '>>' : illegal, right operand has type 'double'
F:\教育教学\练习\1.cpp(12) : error C2297: '<<' : illegal, right operand has type 'char [11]'
F:\教育教学\练习\1.cpp(14) : error C2065: 'd' : undeclared identifier
F:\教育教学\练习\1.cpp(15) : error C2143: syntax error : missing ')' before '{'
F:\教育教学\练习\1.cpp(15) : error C2143: syntax error : missing ';' before ')'
F:\教育教学\练习\1.cpp(15) : error C2143: syntax error : missing ';' before ')'
F:\教育教学\练习\1.cpp(15) : error C2143: syntax error : missing ';' before '{'
F:\教育教学\练习\1.cpp(18) : error C2065: 'x' : undeclared identifier
F:\教育教学\练习\1.cpp(18) : error C2065: 'b' : undeclared identifier
F:\教育教学\练习\1.cpp(18) : error C2065: 'a' : undeclared identifier
F:\教育教学\练习\1.cpp(19) : error C2297: '<<' : illegal, right operand has type 'char [8]'
F:\教育教学\练习\1.cpp(23) : error C2065: 'x1' : undeclared identifier
F:\教育教学\练习\1.cpp(23) : error C2065: 'c' : undeclared identifier
F:\教育教学\练习\1.cpp(23) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
F:\教育教学\练习\1.cpp(24) : error C2065: 'x2' : undeclared identifier
F:\教育教学\练习\1.cpp(24) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
F:\教育教学\练习\1.cpp(25) : error C2297: '<<' : illegal, right operand has type 'char [5]'
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)
到底错在哪些地方??
另外这问题可以用到函数的递归这个现象吗?该怎么用?我不清楚啊
能给我一些提示吗 谢谢大家啊
搜索更多相关主题的帖子: 一元二次方程 
2009-07-17 14:22
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
收藏
得分:0 
谢谢LS2位,可我按你们说的弄成了这样:
#include "iostream"
#include "math.h"
using namespace std;
double main()
{
    double a,b,c,d,x,x1,x2;
    do
    {
    cout<<"请输入一元二次方程的a、b、c"<<endl;
    cin>>a>>b>>c;
    d=b*b-4*a*c;
    if(d<0)
    {
        cout<<"此方程无解"<<endl;
    }
    }while(d>=0);
    {
        if(d==0)
        {
            x=b/2/a;
            cout<<"x1=x2=-"<<x<<endl;
        }
        else
        {
            x1=b/2/a+sqrt(b*b-4*a*c)/2/a;
            x2=b/2/a-sqrt(b*b-4*a*c)/2/a;
            cout<<"x1=-"<<x1<<";"<<"x2=-"<<x2<<endl;
        }
    }
    return 0;
}
编译成功了,可是无论我输入什么1 2 1,还是1 4 4这种的都反复叫我重新输入.怎么办?是不是我还有什么地方没按你们改呢?
2009-07-17 16:37
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
收藏
得分:0 
额,楼上的jackie1918,您叫我写成#include <math>这样的话在编译的时候还是成为fatal error C1083: Cannot open include file: 'math': No such file or directory了。
2009-07-17 17:09
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
收藏
得分:0 
哦,谢谢。太谢谢各位了。
2009-07-17 17:28
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
收藏
得分:0 
3楼的lintaoyn,抱歉啊。我本来想给你分数的。可为什么却没有可以给我给你分的空格?
2009-07-17 17:31
快速回复:一元二次方程的问题
数据加载中...
 
   



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

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