| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 513 人关注过本帖
标题:我想编写一个求方程 ax^2+bx+c=0 的根的程序。求大侠帮忙看一下哪里错误了。 ...
只看楼主 加入收藏
balancad
Rank: 1
等 级:新手上路
帖 子:19
专家分:6
注 册:2014-4-21
结帖率:80%
收藏
 问题点数:0 回复次数:2 
我想编写一个求方程 ax^2+bx+c=0 的根的程序。求大侠帮忙看一下哪里错误了。
#include<stdio.h>
#include<math.h>
int main()
{
    double a, b, c, dis,x, x1, x2;
    char i;
    scanf_s("%f %f %f", &a, &b, &c);
    dis = b*b-4*a*c;
    if (a == 0)x = --c / b;
    else if (dis >= 0)x1 = -b / 2 * a + sqrt(dis) / 2 * a, x2 = -b / 2 * a - sqrt(dis) / 2 * a;
    else if (dis < 0)dis = -dis, x1 = -b / 2 * a + sqrt(dis) / 2 * a i; , x2 = -b / 2 * a - sqrt(dis) / 2 * a i;
    return 0;
}
搜索更多相关主题的帖子: include double return 
2014-04-21 20:26
Andrew_Lee
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:185
专家分:626
注 册:2014-3-21
收藏
得分:0 
程序代码:
#include<stdio.h>
#include<math.h>
int main()
{
    double a, b, c, dis,x, x1, x2;
  
    scanf("%lf %lf %lf", &a, &b, &c);
    dis = b*b-4*a*c;
    if (a == 0)
    {
        x = -c / b;
        printf("the jie of the fangcheng is %lf\n",x);
        return 0;
    }
    if (dis >= 0)
    {
        x1 = -b / (2 * a) + sqrt(dis) / (2 * a);

        x2 = -b / (2 * a) - sqrt(dis) / (2 * a);
        printf("the jie of the fang cheng is x1=%lf\tx2=%lf\n",x1,x2);
        return 0;
    }
    else
    {
        dis = -dis;
        x1 = -b / (2 * a);
        x2 = sqrt(dis) / (2 * a);
        printf("the jie of the fang cheng is x1=%lf+j%lf\tx2=%lf-j%lf\n",x1,x2,x1,x2);
        return 0;
    }
} 
2014-04-21 21:07
hc407647719
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2014-4-21
收藏
得分:0 
ding
2014-04-21 21:39
快速回复:我想编写一个求方程 ax^2+bx+c=0 的根的程序。求大侠帮忙看一下哪里错 ...
数据加载中...
 
   



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

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