c++二元一次方和求解程序
- #ifndef WYZ_WYZ_2
- #define WYZ_WYZ_2
- #include<iostream>
- #include<cmath>
- template<typename Any>
- void eqution(Any a,Any b,Any c)
- {
- using std::cout;
- using std::endl;
- Any d=b*b-4*a*c;
- if(d>0)
- {
- float sqrtd=sqrtf(d);
- cout<<"有兩個實根"
- <<(-b+sqrtd)/(2*a)<<"和"
- <<(-b-sqrtd)/(2*a)<<endl;
- }
- else if(d==0)
- cout<<"只有一個根"
- <<-b/(2*a)<<endl;
- else cout<<"有根是復雜的"
- <<endl<<"真正的部分是"
- <<-b/(2*a)<<endl
- <<"有虛部"
- <<sqrtf(-d)/(2*a)<<endl;
- }
- template<> void eqution(char a,char b,char c)
- {
- std::cout<<"輸入錯誤"<<std::endl;
- }
- #endif
-
- //..............................................................
- /*#include"789.h"
- #include<iostream>
- int main()
- {
- int a,b,c;
- std::cin>>a>>b>>c;
- eqution(a,b,c);
- return 0;
- }*/
復制代碼
|