diff options
Diffstat (limited to 'Practical_C_Programming/Chapter_6_4.ipynb')
-rw-r--r-- | Practical_C_Programming/Chapter_6_4.ipynb | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/Practical_C_Programming/Chapter_6_4.ipynb b/Practical_C_Programming/Chapter_6_4.ipynb new file mode 100644 index 00000000..22907862 --- /dev/null +++ b/Practical_C_Programming/Chapter_6_4.ipynb @@ -0,0 +1,104 @@ +{ + "metadata": { + "name": "Chapter 6" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": "Chapter 6: Decision and control statements" + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 6.1, Page number: 114" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 6.1.py\n# To print the Fibonacci series upto 100\n\n\n# Variable declaration\nold_number = 1\ncurrent_number = 1\n\nprint ('1')\n\n# Calculation and result\nwhile (current_number < 100) :\n print (current_number)\n next_number = current_number + old_number\n\n old_number = current_number\n current_number = next_number", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "1\n1\n2\n3\n5\n8\n13\n21\n34\n55\n89\n" + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 6.2, Page number: 115" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 6.2.py\n# To calculate the number of items entered\n\n\n# Variable declaration\ntotal = 0\ni = 0\n\n# Calculation\nwhile (i < 10) :\n item = 1\n\n if item == 0 :\n break\n\n total += item\n print ('Total: %d' % total)\n i = i + 1\n \n# Result\nprint ('Final total: %d' % total)", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Total: 1\nTotal: 2\nTotal: 3\nTotal: 4\nTotal: 5\nTotal: 6\nTotal: 7\nTotal: 8\nTotal: 9\nTotal: 10\nFinal total: 10\n" + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 6.3, Page number: 116" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 6.3.py\n# To calculate the total number of items entered and omit the negative items\n\n\n# Variable declaration\ntotal = 0\nminus_items = 0\ni = 0\n\n# Calculation\nwhile (i < 10) :\n item = 1\n \n if item == 0 :\n break\n\n if item < 0 :\n minus_items += 1\n continue\n\n total += item\n print ('Total: %d' % total)\n i = i + 1\n \n# Result\nprint ('Final total: %d' % total)\nprint ('with %d negative items omitted' % minus_items)", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "Total: 1\nTotal: 2\nTotal: 3\nTotal: 4\nTotal: 5\nTotal: 6\nTotal: 7\nTotal: 8\nTotal: 9\nTotal: 10\nFinal total: 10\nwith 0 negative items omitted\n" + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": "Example 6.4, Page number: 118" + }, + { + "cell_type": "code", + "collapsed": false, + "input": "# Example 6.4.py\n# To calculate the number of dollars owed\n\n\n# Variable declaration\nbalance_owed = 100\n\n# Calculation and result\nif balance_owed == 0 :\n print ('You owe nothing.')\nelse :\n print ('You owe %d dollars.' % balance_owed)", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "You owe 100 dollars.\n" + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file |