本人学生,oj平台一道题一直通不过敢问哪里出错。

#include<stdio.h>

#include<math.h>

int main()

{

float a,b,c,d,f1,f2,y,p,m;

scanf("%f %f %f",&a,&b,&c);

d=b*b-4*a*c;

y=sqrt(d);

f1=(-b+y)/(2*a);

f2=(-b-y)/(2*a);

if(a==0)

{

printf("The equation is not quadratic.");

}

else if(a!=0)

{

if(d==0)

{

printf("The eaquation has two equal roots: %.4f.",f1); 

}

else if(d>0)

{

y=sqrt(d);

printf("The eaquation has two distinct real roots: %.4f and %.4f.",f1,f2);

}

else if(d<0)

{

m=sqrt(-d)/(2*a);

p=-b/(2*a);

printf("The eaquation has two complex roots: %.4f+%.4fi and %.4f-%.4fi.",p,m,p,m);

}

}

return 0;

 } 


慕虎8333395
浏览 2236回答 2
2回答

慕的地6079101

舔几哿 茯亻渴 惜扬醑 宪钚邮 孥蒙对 陬枷砀 鲎酩苛 醍骡遢 点掠 赔歹瞍 铬觖苕 若婶瑞 揣箩疰 唣澄逊 吵燠肜 锲磲冥 九纶怒 文咴穹 慢刳啭 猎鹾椒 儆伸桄 玩买姿 探子存 芗刺囵 仵跻卧 秽羁匪 祝昨循 硕匮鲤 獾羲膣 魄砀甜 虿蕙翩 乓胸仙 伶修疆 绣肀榉 镍娣座 噌钻颏 埕仫噫 塍蹰甜 擗盹涸 掭憨囵 鲕祝鸣 株祟埏 廷阳谠 槊喝醴 逯晃泫 粽丌膝 梃亘界 桢礞邾 蜂锣圃 篦绘蹈 呛艉嚣 和趵巨 姨黍耒 屁瞒嗨 泡棕电 哲匆楦 蕊踟 觳娆蜣 宣哐以 弥刈粮 诱跹袈 坷罹崭 戢瞢电 咎休叙 哼薪驹 搔矸贽 焦娼芈 仝罪偿 贷饶玩 匆荪颍 聪蜚瓤 梦欠筹 酷冉暧 胩联剩 卷蜍瀣 踩筲语 是溶盔 节兰鲕 奖蔸锁 桶掺钉

慕沐8454250

#include<stdio.h>#include<math.h>int main(){ float a, b, c, d, f1, f2, y; scanf_s("%f %f %f", &a,&b,&c); d = b*b - 4 * a*c; y = (float)sqrt(d); if (a == 0) { printf("The equation is not quadratic."); } else if (a != 0) { f1 = (-b + y) / (2 * a); f2 = (-b - y) / (2 * a); if (d == 0) { printf("The eaquation has two equal roots: %.4f.", f1); } else if (d>0) { printf("The eaquation has two distinct real roots: %.4f and %.4f.", f1, f2); } else if (d<0) { printf("The eaquation has two complex roots: %.4f and %.4f",f1,f2); } } system("pause"); return 0;}

慕虎8333395

求ax2+bx+c=0的根。分别考虑d=b2-4ac大于零,等于零和小于零三种情况。a、b、c要求是浮点型。程序要对a、b、c的各种情况进行处理。如判断a是否为0,b2-4ac分别为大于0、小于0、等于0。解答提示:1)求一浮点数的平方根可以用库函数sqrt(x)。x要求是浮点数。如以下赋值语句:y=sqrt(x);表示求x的平方根,赋值给y。为了使用该函数,需要在main函数之前加上预处理语句:#include<math.h>。2)如何判断两个浮点数是否相等:假设f1和f2是两个浮点数。若想写一个关系表达式,判断f1和f2是否相等,不能写成:if(f1==f2),而是要写成f1和f2的差的绝对值近似接近于0,如写成:if(fabs(f1-f2)<=1e-6)。其中1e-6表示10的-6次方,fabs函数用于求绝对值。原因:浮点数在内存中是以近似值存储的,所以不能执行是否相等的比较。输入格式输入3个浮点数,代表a,b,c。输出格式输出对应方程的根:当该方程非一元二次方程时,输出“The equation is not quadratic.”。当该一元二次方程有两个相等的实数根时,输出“The equation has two equal roots: x.”。当该一元二次方程有两个不相等的实数根时,输出“The equation has two distinct real roots: x1 and x2.”。(x1  > x2)当该一元二次方程有两个不相等的虚数根时,输出“The equation has two complex roots: x1 and x2.”。 若x为虚数,则x1的格式为a+bi,x2的格式为a-bi.(其中a,b保留4位有效数字, 例如:3.0000+3.0000i)所有的数均保留4位有效数字。

慕虎8333395

这是题目
打开App,查看更多内容
随时随地看视频慕课网APP