diff options
Diffstat (limited to 'Practical_C_Programming/Chapter_10_1.ipynb')
-rw-r--r-- | Practical_C_Programming/Chapter_10_1.ipynb | 230 |
1 files changed, 230 insertions, 0 deletions
diff --git a/Practical_C_Programming/Chapter_10_1.ipynb b/Practical_C_Programming/Chapter_10_1.ipynb new file mode 100644 index 00000000..b3cda55e --- /dev/null +++ b/Practical_C_Programming/Chapter_10_1.ipynb @@ -0,0 +1,230 @@ +{ + "metadata": { + "name": "Chapter 10" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": "Chapter 10: C Preprocessor" + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.1, Page number: 172" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.1.py\n# To print the contents of two arrays upto 10 indices\n\n\n# Variable declaration\ndata = []\ntwice = []\n\n# Calculation and result\nfor index in range (0, 10) :\n data.append(index)\n twice.append(2 * index)\n\nprint (data)\nprint (twice)", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n" + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.2, Page number: 173" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.2.py\n# To print the contents of two arrays upto 20 indices \n\n\n# Variable declaration\ndata = []\ntwice = []\n\n# Calculation and result\nfor index in range (0, 20) :\n data.append(index)\n twice.append(2 * index)\n\nprint (data)\nprint (twice)", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]\n" + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.3, Page number: 175" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.3.py\n# To print the value of variable 'index' \n\n\n# Variable declaration\nBIG_NUMBER = 10 * 10\nindex = 1\n\n# Calculation and result\nwhile (index < BIG_NUMBER) :\n index = index * 8\n print ('%d' % index)", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "8\n64\n512\n" + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.4, Page number: 176" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.4.py\n# To determine the square of ALL_PARTS \n\n\n# Variable declaration\nFIRST_PART = 7\nLAST_PART = 5\nALL_PARTS = FIRST_PART + LAST_PART\n\n# Calculation and result\nprint ('The square of all the parts is %d' % (ALL_PARTS * ALL_PARTS))", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "The square of all the parts is 144\n" + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.5, Page number: 177" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.5.py\n# To print 'Hi there' 10 times \n\n\n# Calculation and result\nfor i in reversed (range(10)) :\n print ('Hi there')", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Hi there\nHi there\nHi there\nHi there\nHi there\nHi there\nHi there\nHi there\nHi there\nHi there\n" + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.6, Page number: 177" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.6.py\n# To print the value of 'size' \n\n\n# Variable declaration\nsize = 10\nfudge = size - 2\n\n# Calculation and result\nsize = fudge\nprint ('Size is %d' % size)", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Size is 8\n" + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.7, Page number: 178" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.7.py\n# To exit the program based on a specific condition \n\n\n# Variable declaration\nimport sys\nvalue = 1\n\n# Calculation and result\nif (value < 0) :\n sys.exit()\n\nprint ('We did not die')", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "We did not die\n" + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.8, Page number: 184" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.8.py\n# To display the square of numbers from 1 to 5 \n\n\n# Function declaration, calculation and result\ndef SQR (x) :\n return x * x\n \nfor counter in range (0, 5) :\n print ('x %d, x squared %d\\n' % (counter + 1, SQR (counter + 1)))", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "x 1, x squared 1\n\nx 2, x squared 4\n\nx 3, x squared 9\n\nx 4, x squared 16\n\nx 5, x squared 25\n\n" + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.9, Page number: 184" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.9.py\n# To display the square of numbers from 1 to 5 \n\n\n# Variable declaration\ncounter = 0\n\n# Function declaration, calculation and result\ndef SQR (x) :\n return x * x\n \nwhile (counter < 5) :\n print ('x %d square %d\\n' % (counter + 1, SQR (counter + 1)))\n counter += 1", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "x 1 square 1\n\nx 2 square 4\n\nx 3 square 9\n\nx 4 square 16\n\nx 5 square 25\n\n" + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 10.10, Page number: 185" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 10.10.py\n# To calculate the reciprocal of numbers from 1 to 9\n\n\n# Function declaration, calculation and result\ndef reciprocal (number) :\n return 1 / number\n \nfor counter in range (1, 10) :\n print ('1/%f = %f\\n' % (counter, reciprocal (counter)))", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "1/1.000000 = 1.000000\n\n1/2.000000 = 0.000000\n\n1/3.000000 = 0.000000\n\n1/4.000000 = 0.000000\n\n1/5.000000 = 0.000000\n\n1/6.000000 = 0.000000\n\n1/7.000000 = 0.000000\n\n1/8.000000 = 0.000000\n\n1/9.000000 = 0.000000\n\n" + } + ], + "prompt_number": 10 + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file |