亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如圖,求解為什么我的答案不對???

如圖,求解為什么我的答案不對???

#include<stdio.h>#include<math.h>float x(int a,int b,float d);float y(int a,int b,float d);int main(){int a,b,c;float d;scanf("%d%d%d",&a,&b,&c);d=b*b-4*a*c;if(d>=0){x(a,b,d);}else{y(a,b,d);}return 0;}float x(int a,int b,float d){float p,q;p=(-b+sqrt(d))/2/a;q=(-b-sqrt(d))/2/a;printf("x1=%.3f x2=%.3f",p,q);}float y(int a,int b,float d){float p,q;p=(-b)/2/a;q=sqrt(-d)/2/a;printf("x1=%.3f+%.3fi x2=%.3f-%.3fi",p,q,p,q); }
查看完整描述

2 回答

?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
int a,b,c;
int t;
//t就是b^2-4ac判斷它和0的大小決定是解否是復數 
cout<<"推出請按Ctrl+c,輸入a,b、c的值\n";
//Ctrl+c是 windows下的文件結束符.在命令行下不是拷貝快捷鍵 

a=b=c=t=0;
//初始化
cin>>a>>b>>c;
//輸入數據 
if(a==0){printf("input error!\n");continue;}
//如果輸入二次項系數為零顯示告訴用戶 
t=b*b-4*a*c;
if(t==0)
cout<<"x1=x2="<<(-b/2a)<<endl;
if (t<0){
cout<<"x1="<<(-b/2.0/a)<<"+"<<(sqrt(-t)/2/a)<<"i"<<setprecision(3)<<endl;
cout<<"x2="<<(-b/2.0/a)<<"-"<<(sqrt(-t)/2/a)<<"i"<<setprecision(3)<<endl;

}
else {
cout<<"x1="<<(-b/2.0/a+sqrt(t)/2/a)<<setprecision(3)<<endl;
cout<<"x2="<<(-b/2.0/a-sqrt(t)/2/a)<<setprecision(3)<<endl;
}

return 0;}

 


查看完整回答
反對 回復 2023-03-21
?
眼眸繁星

TA貢獻1873條經驗 獲得超9個贊


查看完整回答
反對 回復 2023-03-21
  • 2 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號