diff options
Diffstat (limited to 'Let_us_C/chapter-6.ipynb')
-rw-r--r-- | Let_us_C/chapter-6.ipynb | 683 |
1 files changed, 683 insertions, 0 deletions
diff --git a/Let_us_C/chapter-6.ipynb b/Let_us_C/chapter-6.ipynb new file mode 100644 index 00000000..7cf66240 --- /dev/null +++ b/Let_us_C/chapter-6.ipynb @@ -0,0 +1,683 @@ +{
+ "metadata": {
+ "name": "chapter-6.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 6: Data Types Revisted <h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>char Example, Page number: 218<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to demonstrate the range of char'''\n",
+ "\n",
+ "#Variable declaration\n",
+ "ch = 291\n",
+ "\n",
+ "#Result\n",
+ "print \"%d %c\" %( ch, (ch%128) ) \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "291 #\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Range of char, Page number: 218<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to demonstrate the range of an unsigned char'''\n",
+ "\n",
+ "for ch in range(0,256):\n",
+ " print \"%d %c\" %(ch, ch%128 )\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0 \u0000\n",
+ "1 \u0001\n",
+ "2 \u0002\n",
+ "3 \u0003\n",
+ "4 \u0004\n",
+ "5 \u0005\n",
+ "6 \u0006\n",
+ "7 \u0007\n",
+ "8 \b\n",
+ "9 \t\n",
+ "10 \n",
+ "\n",
+ "11 \u000b",
+ "\n",
+ "12 \f",
+ "\n",
+ "13 \r\n",
+ "14 \u000e\n",
+ "15 \u000f\n",
+ "16 \u0010\n",
+ "17 \u0011\n",
+ "18 \u0012\n",
+ "19 \u0013\n",
+ "20 \u0014\n",
+ "21 \u0015\n",
+ "22 \u0016\n",
+ "23 \u0017\n",
+ "24 \u0018\n",
+ "25 \u0019\n",
+ "26 \u001a\n",
+ "27 \u001b\n",
+ "28 \u001c",
+ "\n",
+ "29 \u001d",
+ "\n",
+ "30 \u001e",
+ "\n",
+ "31 \u001f\n",
+ "32 \n",
+ "33 !\n",
+ "34 \"\n",
+ "35 #\n",
+ "36 $\n",
+ "37 %\n",
+ "38 &\n",
+ "39 '\n",
+ "40 (\n",
+ "41 )\n",
+ "42 *\n",
+ "43 +\n",
+ "44 ,\n",
+ "45 -\n",
+ "46 .\n",
+ "47 /\n",
+ "48 0\n",
+ "49 1\n",
+ "50 2\n",
+ "51 3\n",
+ "52 4\n",
+ "53 5\n",
+ "54 6\n",
+ "55 7\n",
+ "56 8\n",
+ "57 9\n",
+ "58 :\n",
+ "59 ;\n",
+ "60 <\n",
+ "61 =\n",
+ "62 >\n",
+ "63 ?\n",
+ "64 @\n",
+ "65 A\n",
+ "66 B\n",
+ "67 C\n",
+ "68 D\n",
+ "69 E\n",
+ "70 F\n",
+ "71 G\n",
+ "72 H\n",
+ "73 I\n",
+ "74 J\n",
+ "75 K\n",
+ "76 L\n",
+ "77 M\n",
+ "78 N\n",
+ "79 O\n",
+ "80 P\n",
+ "81 Q\n",
+ "82 R\n",
+ "83 S\n",
+ "84 T\n",
+ "85 U\n",
+ "86 V\n",
+ "87 W\n",
+ "88 X\n",
+ "89 Y\n",
+ "90 Z\n",
+ "91 [\n",
+ "92 \\\n",
+ "93 ]\n",
+ "94 ^\n",
+ "95 _\n",
+ "96 `\n",
+ "97 a\n",
+ "98 b\n",
+ "99 c\n",
+ "100 d\n",
+ "101 e\n",
+ "102 f\n",
+ "103 g\n",
+ "104 h\n",
+ "105 i\n",
+ "106 j\n",
+ "107 k\n",
+ "108 l\n",
+ "109 m\n",
+ "110 n\n",
+ "111 o\n",
+ "112 p\n",
+ "113 q\n",
+ "114 r\n",
+ "115 s\n",
+ "116 t\n",
+ "117 u\n",
+ "118 v\n",
+ "119 w\n",
+ "120 x\n",
+ "121 y\n",
+ "122 z\n",
+ "123 {\n",
+ "124 |\n",
+ "125 }\n",
+ "126 ~\n",
+ "127 \u007f\n",
+ "128 \u0000\n",
+ "129 \u0001\n",
+ "130 \u0002\n",
+ "131 \u0003\n",
+ "132 \u0004\n",
+ "133 \u0005\n",
+ "134 \u0006\n",
+ "135 \u0007\n",
+ "136 \b\n",
+ "137 \t\n",
+ "138 \n",
+ "\n",
+ "139 \u000b",
+ "\n",
+ "140 \f",
+ "\n",
+ "141 \r\n",
+ "142 \u000e\n",
+ "143 \u000f\n",
+ "144 \u0010\n",
+ "145 \u0011\n",
+ "146 \u0012\n",
+ "147 \u0013\n",
+ "148 \u0014\n",
+ "149 \u0015\n",
+ "150 \u0016\n",
+ "151 \u0017\n",
+ "152 \u0018\n",
+ "153 \u0019\n",
+ "154 \u001a\n",
+ "155 \u001b\n",
+ "156 \u001c",
+ "\n",
+ "157 \u001d",
+ "\n",
+ "158 \u001e",
+ "\n",
+ "159 \u001f\n",
+ "160 \n",
+ "161 !\n",
+ "162 \"\n",
+ "163 #\n",
+ "164 $\n",
+ "165 %\n",
+ "166 &\n",
+ "167 '\n",
+ "168 (\n",
+ "169 )\n",
+ "170 *\n",
+ "171 +\n",
+ "172 ,\n",
+ "173 -\n",
+ "174 .\n",
+ "175 /\n",
+ "176 0\n",
+ "177 1\n",
+ "178 2\n",
+ "179 3\n",
+ "180 4\n",
+ "181 5\n",
+ "182 6\n",
+ "183 7\n",
+ "184 8\n",
+ "185 9\n",
+ "186 :\n",
+ "187 ;\n",
+ "188 <\n",
+ "189 =\n",
+ "190 >\n",
+ "191 ?\n",
+ "192 @\n",
+ "193 A\n",
+ "194 B\n",
+ "195 C\n",
+ "196 D\n",
+ "197 E\n",
+ "198 F\n",
+ "199 G\n",
+ "200 H\n",
+ "201 I\n",
+ "202 J\n",
+ "203 K\n",
+ "204 L\n",
+ "205 M\n",
+ "206 N\n",
+ "207 O\n",
+ "208 P\n",
+ "209 Q\n",
+ "210 R\n",
+ "211 S\n",
+ "212 T\n",
+ "213 U\n",
+ "214 V\n",
+ "215 W\n",
+ "216 X\n",
+ "217 Y\n",
+ "218 Z\n",
+ "219 [\n",
+ "220 \\\n",
+ "221 ]\n",
+ "222 ^\n",
+ "223 _\n",
+ "224 `\n",
+ "225 a\n",
+ "226 b\n",
+ "227 c\n",
+ "228 d\n",
+ "229 e\n",
+ "230 f\n",
+ "231 g\n",
+ "232 h\n",
+ "233 i\n",
+ "234 j\n",
+ "235 k\n",
+ "236 l\n",
+ "237 m\n",
+ "238 n\n",
+ "239 o\n",
+ "240 p\n",
+ "241 q\n",
+ "242 r\n",
+ "243 s\n",
+ "244 t\n",
+ "245 u\n",
+ "246 v\n",
+ "247 w\n",
+ "248 x\n",
+ "249 y\n",
+ "250 z\n",
+ "251 {\n",
+ "252 |\n",
+ "253 }\n",
+ "254 ~\n",
+ "255 \u007f\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Scope and Life of Automatic Variable, Page number: 225<h3>\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to illustrate the scope and life of an automatic variable'''\n",
+ "\n",
+ "#Variable declaration\n",
+ "i = 1 #auto int\n",
+ "\n",
+ "def b2 (i):\n",
+ " print i \n",
+ "\n",
+ "def b3 (i):\n",
+ " print i \n",
+ "\n",
+ "\n",
+ "def b1 (i):\n",
+ " print i \n",
+ " b2(i)\n",
+ " b3(i)\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "b1(i)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n",
+ "1\n",
+ "1\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Scope and Life of Automatic Variable, Page number: 226<h3>\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to illustrate the scope and life of an automatic variable'''\n",
+ "\n",
+ "#Variable declaration\n",
+ "i = 1 #auto int\n",
+ "\n",
+ "def b2 (i):\n",
+ " i = 2 # auto int \n",
+ " print i \n",
+ "\n",
+ "def b3 (i):\n",
+ " i = 3 #auto int \n",
+ " print i \n",
+ "\n",
+ "\n",
+ "def b1 (i):\n",
+ " b3(i)\n",
+ " b2(i)\n",
+ " print i \n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "b1(i)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n",
+ "2\n",
+ "1\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Different Data Types, Page number: 220<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program that puts to use all the data types'''\n",
+ "\n",
+ "#char\n",
+ "#c,d = raw_input(\"char: \").split()\n",
+ "c = 'a'\n",
+ "d = 'b'\n",
+ "print \"%c %c\" %( c, d )\n",
+ "\n",
+ "#int \n",
+ "#i,j = raw_input( \"int: \").split()\n",
+ "i = 333\n",
+ "j = 288\n",
+ "print \"%d %u\"%( i, j ) \n",
+ "\n",
+ "#short int \n",
+ "#,l = raw_input( \"short int: \" ).split()\n",
+ "k = 2\n",
+ "l = 1\n",
+ "print \"%d %u \" %(k, l ) \n",
+ "\n",
+ "#long int \n",
+ "#m,n = raw_input( \"long int: \" ).split()\n",
+ "m = 73277727727\n",
+ "n = 189189819891\n",
+ "print \"%ld %lu\"%( m, n ) \n",
+ "\n",
+ "\n",
+ "#float, double, long double\n",
+ "from decimal import Decimal \n",
+ "#x,y,z = raw_input ( \"float double long double: \").split()\n",
+ "x = 72.12\n",
+ "y = Decimal(8282910.0109010)\n",
+ "z = Decimal(29189999111.128918918)\n",
+ "print x, y, z "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "a b\n",
+ "333 288\n",
+ "2 1 \n",
+ "73277727727 189189819891\n",
+ "72.12 8282910.0109010003507137298583984375 29189999111.128917694091796875\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Auto Increment, Page number: 228<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to understand the difference\n",
+ "between the automatic and static storage classes.'''\n",
+ "\n",
+ "#function definition \n",
+ "def increment( ):\n",
+ " i = 1 #auto int\n",
+ " print i \n",
+ " i = i + 1 \n",
+ "\n",
+ "#function calls\n",
+ "increment( )\n",
+ "increment( )\n",
+ "increment( )\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n",
+ "1\n",
+ "1\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Static Increment, Page number: 228<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to understand the difference\n",
+ "between the automatic and static storage classes.'''\n",
+ "\n",
+ "#function definition \n",
+ "def increment(i = [1]): #static int \n",
+ " print i[0] \n",
+ " i[0] += 1 \n",
+ "\n",
+ "#function calls\n",
+ "increment()\n",
+ "increment()\n",
+ "increment()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n",
+ "2\n",
+ "3\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Static Storage Class, Page number: 229<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to illustrate the advantages of using static storage class'''\n",
+ "\n",
+ "\n",
+ "#function definition\n",
+ "def fun( ):\n",
+ " k = 35 \n",
+ " return (k)\n",
+ "\n",
+ "j = fun( ) #function call\n",
+ "print j #result\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "35\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>External Storage Class, Page number: 231<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to illustrate the extrnal storage class'''\n",
+ "\n",
+ "#Variable declaration \n",
+ "i = [0] # external variable\n",
+ "\n",
+ "#Function definitions \n",
+ "def increment(i = [0]):\n",
+ " i[0] += 1\n",
+ " print \"on incrementing i = \", i[0] \n",
+ "\n",
+ "\n",
+ "def decrement(i = [2]):\n",
+ " i[0] -= 1\n",
+ " print \"on decrementing i = \", i[0] \n",
+ " \n",
+ "\n",
+ "\n",
+ "print \"i = \", i[0]\n",
+ "#function calls\n",
+ "increment() \n",
+ "increment() \n",
+ "decrement() \n",
+ "decrement() "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "i = 0\n",
+ "on incrementing i = 1\n",
+ "on incrementing i = 2\n",
+ "on decrementing i = 1\n",
+ "on decrementing i = 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file |