summaryrefslogtreecommitdiff
path: root/Practical_C_Programming/Chapter_5_4.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Practical_C_Programming/Chapter_5_4.ipynb')
-rw-r--r--Practical_C_Programming/Chapter_5_4.ipynb230
1 files changed, 230 insertions, 0 deletions
diff --git a/Practical_C_Programming/Chapter_5_4.ipynb b/Practical_C_Programming/Chapter_5_4.ipynb
new file mode 100644
index 00000000..37c16908
--- /dev/null
+++ b/Practical_C_Programming/Chapter_5_4.ipynb
@@ -0,0 +1,230 @@
+{
+ "metadata": {
+ "name": "Chapter 5"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Chapter 5: Arrays, qualifiers, and reading numbers"
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.1, Page number: 84"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.1.py\n# To print the total and average of five data items\n\n\n# Variable declaration\ndata = [ 34.0, 27.0, 45.0, 82.0, 22.0 ]\n\n# Calculation\ntotal = data[0] + data[1] + data[2] + data[3] + data[4]\naverage = total/5.0\n\n# Result\nprint ('Total %f Average %f' % (total, average))",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Total 210.000000 Average 42.000000\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.2, Page number: 87"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.2.py\n# To print the name 'Sam'\n\n\n# Variable declaration\nname = 'Sam'\n\n# Result\nprint ('The name is %s' % name)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "The name is Sam\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.3, Page number: 88"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.3.py\n# To print the full name of a person\n\n\n# Variable declaration\nfirst = 'Steve'\nlast = 'Oualline'\n\n# Calculation\nfull_name = first + ' ' + last\n\n# Result\nprint ('The full name is %s' % full_name)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "The full name is Steve Oualline\n"
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.4, Page number: 89"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.4.py\n# To calculate the length of a line\n\n\n# Variable declaration\nline = 'hello world'\n\n# Result\nprint ('The length of the line is %d' % len(line))",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "The length of the line is 11\n"
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.5, Page number: 90"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.5.py\n# To display the first and last names of a person\n\n\n# Variable declaration\nfirst = 'Steve'\nlast = 'Oualline'\n\n# Calculation\nfull = first + ' ' + last\n\n# Result\nprint ('The name is %s' % full)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "The name is Steve Oualline\n"
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.6, Page number: 91"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.6.py\n# To display the first and last names of a person\n\n\n# Variable declaration\nfirst = 'Steve'\nlast = 'Oualline'\n\n# Calculation\nfull = first + ' ' + last\n\n# Result\nprint ('The name is %s' % full)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "The name is Steve Oualline\n"
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.7, Page number: 93"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.7.py\n# To display the values of the elements of a 2-D array\n\n\n# Variable declaration\narray = [[0 for x in range(5)] for x in range(5)]\narray[0][0] = 0 * 10 + 0\narray[0][1] = 0 * 10 + 1\narray[1][0] = 1 * 10 + 0\narray[1][1] = 1 * 10 + 1\narray[2][0] = 2 * 10 + 0\narray[2][1] = 2 * 10 + 1\n\n# Result\nprint ('array[0]')\nprint (array[0][0])\nprint (array[0][1])\nprint ('\\n')\n\nprint ('array[1]')\nprint (array[1][0])\nprint (array[1][1])\nprint ('\\n')\n\nprint ('array[2]')\nprint (array[2][0])\nprint (array[2][1])\nprint ('\\n')",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "array[0]\n0\n1\n\n\narray[1]\n10\n11\n\n\narray[2]\n20\n21\n\n\n"
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.8, Page number: 94"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.8.py\n# To print the twice of a value\n\n\n# Variable declaration\nline = 4\n\n# Result\nprint ('Twice %d is %d' % (line, line * 2))",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Twice 4 is 8\n"
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.9, Page number: 95"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.9.py\n# To calculate the area of a triangle\n\n\n# Variable declaration\nwidth = 12\nheight = 10\n\n# Calculation\narea = (width * height) / 2\n\n# Result\nprint ('The area is %d' % area)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "The area is 60\n"
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "Example 5.10, Page number: 107"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "# Example 5.10.py\n# To calculate the area of a triangle\n\n\n# Variable declaration\nwidth = 4\nheight = 6\n\n# Calculation\narea = (width * height) / 2\n\n# Result\nprint ('The area is %d' % area)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "The area is 12\n"
+ }
+ ],
+ "prompt_number": 13
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file