標(biāo)題: c++二元一次方和求解程序 [打印本頁(yè)]

作者: 51hei社區(qū)    時(shí)間: 2016-1-10 23:19
標(biāo)題: c++二元一次方和求解程序

c++二元一次方和求解程序


  1. #ifndef WYZ_WYZ_2
  2. #define WYZ_WYZ_2
  3. #include<iostream>
  4. #include<cmath>
  5. template<typename Any>
  6. void eqution(Any a,Any b,Any c)
  7. {
  8. using std::cout;
  9. using std::endl;

  10.    Any d=b*b-4*a*c;
  11.    if(d>0)
  12.    {
  13.     float sqrtd=sqrtf(d);
  14.     cout<<"有兩個(gè)實(shí)根"
  15.     <<(-b+sqrtd)/(2*a)<<"和"
  16.      <<(-b-sqrtd)/(2*a)<<endl;
  17.    }
  18.    else if(d==0)
  19.     cout<<"只有一個(gè)根"
  20.     <<-b/(2*a)<<endl;
  21.    else cout<<"有根是復(fù)雜的"
  22.     <<endl<<"真正的部分是"
  23.     <<-b/(2*a)<<endl
  24.     <<"有虛部"
  25.     <<sqrtf(-d)/(2*a)<<endl;
  26. }

  27. template<> void eqution(char a,char b,char c)
  28. {
  29. std::cout<<"輸入錯(cuò)誤"<<std::endl;
  30. }
  31. #endif
  32.   
  33. //..............................................................
  34. /*#include"789.h"
  35. #include<iostream>
  36. int main()
  37. {
  38. int a,b,c;
  39. std::cin>>a>>b>>c;
  40. eqution(a,b,c);

  41. return 0;
  42. }*/
復(fù)制代碼








歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1