A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© taolove 中级黑马   /  2015-6-13 12:16  /  900 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

#include<stdio.h>
#include<math.h>
int main(){
      
             double a,b,c,x1,x2;
         scanf("%lf,%lf,%lf",&a,&b,&c);
         printf("%lfx^2+%lfx+%lf=0",a,b,c);
                  if(b*b-4*a*c>0){
                          x1=(-b-sqrt(b*b-4*a*c))/2;

              x2=(-b+sqrt(b*b-4*a*c))/2;

                          printf("x1=%.2lf,x2=%.2lf,x1,x2);

                          }
                  else if(b*b-4*a*c==0){
                          x1=x2=-b/2;
                          printf("x1=x2=%.2lf");
                  }else
                          {printf("此方程无解!");}
return 0;
}

6 个回复

倒序浏览
#include<stdio.h>
#include<math.h>
int main(){
      
             double a,b,c,x1,x2;
         scanf("%lf,%lf,%lf",&a,&b,&c);
         printf("%lfx^2+%lfx+%lf=0",a,b,c);
                  if(b*b-4*a*c>0){
                          x1=(-b-sqrt(b*b-4*a*c))/2;

              x2=(-b+sqrt(b*b-4*a*c))/2;

                          printf("x1=%.2lf,x2=%.2lf,x1,x2);

                          }
                  else if(b*b-4*a*c==0){
                          x1=x2=-b/2;
                          printf("x1=x2=%.2lf",x1);}else
                          {printf("此方程无解!");}
return 0;
}
回复 使用道具 举报
本帖最后由 fanxing 于 2015-6-13 13:11 编辑

第二个printf少了个双引号

回复 使用道具 举报
//顺便排了一下版,这回OK了:)

#include<stdio.h>
#include<math.h>

int main(){
       
   double a, b, c, x1, x2;
       
   scanf("%lf, %lf, %lf", &a, &b, &c);
   printf("%lfx^2 + %lfx + %lf = 0\n", a, b, c);

   if(b * b - 4 * a * c > 0){
                x1 = (-b - sqrt(b * b - 4 * a * c)) / 2;
                x2 = (-b + sqrt(b * b - 4 * a * c)) / 2;
                printf("x1 = %.2lf\n, x2 = %.2lf\n", x1, x2);
        }
   else if(b * b - 4 * a * c==0){
                        x1 = x2 = -b / 2;
                      printf("x1 = x2 = %.2lf\n", x1);
                    }else{
                        printf("此方程无解!");
                 }
        return 0;
}
回复 使用道具 举报
fanxing 发表于 2015-6-13 13:08
//顺便排了一下版,这回OK了

#include

谢谢,已经解决
回复 使用道具 举报
这尼玛是什么鬼
回复 使用道具 举报
表示无语了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马