📄 exa_2656.htm
字号:
<HTML><HEAD><TITLE>20.3 Example Program - Roots of a Polynomial</TITLE></HEAD><BODY><A HREF="ug1.htm"><IMG SRC="images/banner.gif"></A><BR><A HREF="cre_7274.htm"><IMG SRC="images/prev.gif"></A><A HREF="booktoc1.htm"><IMG SRC="images/toc.gif"></A><A HREF="tindex1.htm"><IMG SRC="images/tindex.gif"></A><A HREF="num_8453.htm"><IMG SRC="images/next.gif"></A><BR><STRONG>Click on the banner to return to the user guide home page.</STRONG><H2>20.3 Example Program - Roots of a Polynomial</H2><A HREF="sidebar1.htm#sidebar79"><IMG SRC="images/note.gif" BORDER=0> <STRONG>Obtaining the Sample Program</STRONG></A><P>The roots of a polynomial <SAMP>a x2 + b x + c = 0</SAMP> are given by the formula:</P><P><SAMP>x = (-b _ sqrt(b2 - 4ac))/2a</SAMP></P><P>The following program takes as input three double precision numbers, and returns the complex roots as a pair of values.</P><PRE>typedef complex<double> dcomplex;pair<dcomplex, dcomplex> quadratic (dcomplex a, dcomplex b, dcomplex c) // return the roots of a quadratic equation{ dcomplex root = sqrt(b * b - 4.0 * a * c); a *= 2.0; return make_pair( (-b + root)/a, (-b - root)/a);}</PRE><BR><HR><A HREF="cre_7274.htm"><IMG SRC="images/prev.gif"></A> <A HREF="booktoc1.htm"><IMG SRC="images/toc.gif"></A><A HREF="tindex1.htm"><IMG SRC="images/tindex.gif"></A><A HREF="num_8453.htm"><IMG SRC="images/next.gif"></A><P>©Copyright 1996, Rogue Wave Software, Inc.</P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -