導讀 關(guān)于求方程ax2 bx c 0的根 用三個函數(shù)分別求當b2 4ac amp gt 0 等于0這個問題很多朋友還不知道,今天小六來為大家解答以上的問題
關(guān)于求方程ax2 bx c 0的根 用三個函數(shù)分別求當b2 4ac amp gt 0 等于0這個問題很多朋友還不知道,今天小六來為大家解答以上的問題,現(xiàn)在讓我們一起來看看吧!
1、#include #include // b^2-4ac == 0void fun1(double &a,double &b,double &c,double &d){ double ans = -b/(2*a); printf("b^2-4ac == 0 , x1 = x2 = %lf.",ans);}// b^2-4ac > 0void fun2(double &a,double &b,double &c,double &d){ double ans1,ans2; ans1 = (-b+sqrt(d)) / (2*a); ans2 = (-b-sqrt(d)) / (2*a); printf("b^2-4ac > 0 , x1 = %lf , x2 = %lf.",ans1,ans2);}// b^2-4ac < 0void fun3(double &a,double &b,double &c,double &d){ double real,imar; real = -b/(2*a); imar = sqrt(-d) / (2*a); printf("b^2-4ac < 0 , x1 = %lf+%lfi , x2 = %lf-%lfi.",real,imar,real,imar);}int main(){ double a,b,c,d; printf("please input a,b,c."); while(scanf("%lf%lf%lf",&a,&b,&c)!=EOF){ d = b*b-4*a*c; if(d==0) fun1(a,b,c,d); else if(d>0) fun2(a,b,c,d); else fun3(a,b,c,d); printf("please input a,b,c."); }}。
本文分享完畢,希望對大家有所幫助。
標簽:
免責聲明:本文由用戶上傳,如有侵權(quán)請聯(lián)系刪除!