summaryrefslogtreecommitdiff
path: root/_Programming_With_C/chapter3.ipynb
diff options
context:
space:
mode:
Diffstat (limited to '_Programming_With_C/chapter3.ipynb')
-rw-r--r--_Programming_With_C/chapter3.ipynb135
1 files changed, 135 insertions, 0 deletions
diff --git a/_Programming_With_C/chapter3.ipynb b/_Programming_With_C/chapter3.ipynb
new file mode 100644
index 00000000..b9600cd8
--- /dev/null
+++ b/_Programming_With_C/chapter3.ipynb
@@ -0,0 +1,135 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 3: Operators and Expressions<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 3.13, Page number: 3.9 <h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#illustrates the size of respective data type (in C)\n",
+ "\n",
+ "import ctypes as ct\n",
+ "\n",
+ "print \"interger : \",ct.sizeof(ct.c_int())\n",
+ "print \"float : \",ct.sizeof(ct.c_float())\n",
+ "print \"double : \",ct.sizeof(ct.c_double())\n",
+ "print \"character : \",ct.sizeof(ct.c_char())\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "interger : 4\n",
+ "float : 4\n",
+ "double : 8\n",
+ "character : 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 3.30, Page number: 3.19<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# to calculate the roots of quadratic equation\n",
+ "\n",
+ "\n",
+ "print \"for the equation ax^2+bx+c \\n\"\n",
+ "\n",
+ "a=2\n",
+ "b=6\n",
+ "c=3\n",
+ "\n",
+ "root=(b*b-4*a*c)**0.5\n",
+ "x1=(-b + root)/(2*a)\n",
+ "x2=(-b - root)/(2*a)\n",
+ "\n",
+ "print \"x1=\",x1\n",
+ "print \"x2=\",x2\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "for the equation ax^2+bx+c \n",
+ "\n",
+ "x1= -0.633974596216\n",
+ "x2= -2.36602540378\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 3.31, Page number: 3.20<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# to convert a lower case char to upper case\n",
+ "\n",
+ "\n",
+ "\n",
+ "lower=\"l\"\n",
+ "upper=lower.upper()\n",
+ "print upper\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "L\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file