diff options
Diffstat (limited to 'C_Programming:_A_Modern_Approach_by_K.N._King/Chapter27.ipynb')
-rwxr-xr-x | C_Programming:_A_Modern_Approach_by_K.N._King/Chapter27.ipynb | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter27.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter27.ipynb new file mode 100755 index 00000000..15629cee --- /dev/null +++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter27.ipynb @@ -0,0 +1,72 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:d596457391df308a57bb59fde4173c6f3b60829cc798d3f2ffccce6ed1d54b31"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 27: Additional C99 Support for Mathematics"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example quadratic.c, Page 723"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import cmath\n",
+ "\n",
+ "a =5\n",
+ "b = 2\n",
+ "c = 1\n",
+ "\n",
+ "# calculate the discriminant\n",
+ "d = (b**2) - (4*a*c)\n",
+ "\n",
+ "# find two solutions\n",
+ "sol1 = (-b-cmath.sqrt(d))/(2*a)\n",
+ "sol2 = (-b+cmath.sqrt(d))/(2*a)\n",
+ "\n",
+ "print('root1 = {0} \\nroot2 = {1}'.format(sol1,sol2))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "root1 = (-0.2-0.4j) \n",
+ "root2 = (-0.2+0.4j)\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file |