| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 321 人关注过本帖
标题:oj题,求错误
取消只看楼主 加入收藏
A1726542850
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-11-21
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
oj题,求错误
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define X 0.000001
int i=1;
int main()
{
    double a,b,c;
    double t,t1,x1,x2,x3;
    while(1)
    {
        scanf("%lf",&a);
        if(fabs(a)<X) break;
        else
        {   scanf("%lf%lf",&b,&c);
            t=b*b-4*a*c;
            t1=sqrt(fabs(b*b-4*a*c));
            x1=-t1/(2*a);
            x2=+t1/(2*a);
            x3=-b/(2*a);
            if(a == 1||a== -1)printf("Case %d :\nx^2",i);
            else printf("Case %d :\n%gx^2",i,fabs(a));
            if(a>X)
            {
                if(b>X) printf(" + %gx",b);
                else if(fabs(b)<X) ;
                else  printf(" - %gx",-b);
                if(c>X) printf(" + %g = 0\n",c);
                else if(fabs(c)<X) printf(" = 0\n");
                else  printf(" - %g = 0\n",-c);
            }
            if(a<X)
            {
                if(b>X) printf(" - %gx",b);
                else if(fabs(b)<X) ;
                else  printf(" + %gx",-b);
                if(c>X) printf(" - %g = 0\n",c);
                else if(fabs(c)<X) printf(" = 0\n");
                else  printf(" + %g = 0\n",-c);
            }
              if(fabs(b)<X&&fabs(c)<X) {printf("only one real root : 0\n\n");continue;}
           else{
            if(t>X)printf("two real roots : %g, %g\n\n",x3+x2,x3+x1);
            if(fabs(t)<X)printf("only one real root : %g\n\n",x1+x3);
            if(t<-X)
                {
                printf("two imaginary roots : ");
                if(fabs(x3)<X&&x2>X&&x2!=1) printf("%gi, ",x2);
                if(fabs(x3)<X&&x2>X&&x2==1) printf("i, ");
                if(fabs(x3)<X&&x2<-X&&x2!=-1) printf("%gi, ",x2);
                if(fabs(x3)<X&&x2<-X&&x2==-1) printf("-i, ");

                if(fabs(x3)>X&&x2<-X&&x2!=-1) printf("%g-%gi, ",x3,fabs(x2));
                if(fabs(x3)>X&&x2<-X&&x2==-1) printf("%g-i, ",x3,fabs(x2));
                if(fabs(x3)>X&&x2>X&&x2==1) printf("%g+i, ",x3,x2);
                if(fabs(x3)>X&&x2>X&&x2!=1) printf("%g+%gi, ",x3,x2);
                /* second */
                if(fabs(x3)<X&&x1>X&&x1!=1) printf("%gi\n\n",x1);
                if(fabs(x3)<X&&x1>X&&x1==1) printf("i\n\n");
                if(fabs(x3)<X&&x1<-X&&x1!=-1) printf("%gi\n\n",x1);
                if(fabs(x3)<X&&x1<-X&&x1==-1) printf("-i\n\n");

                if(fabs(x3)>X&&x1<-X&&x1!=-1) printf("%g-%gi\n\n",x3,fabs(x1));
                if(fabs(x3)>X&&x1<-X&&x1==-1) printf("%g-i\n\n",x3,fabs(x1));
                if(fabs(x3)>X&&x1>X&&x1==1) printf("%g+i\n\n",x3,x1);
                if(fabs(x3)>X&&x1>X&&x1!=1) printf("%g+%gi\n\n",x3,x1);
                }
            }
        }
        i++;
    }
}
搜索更多相关主题的帖子: include double 
2015-11-23 13:47
A1726542850
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-11-21
收藏
得分:0 
计算一元二次方程
2015-11-23 13:48
快速回复:oj题,求错误
数据加载中...
 
   



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

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