{
 "metadata": {
  "name": "",
  "signature": "sha256:1970948843f0abe57577274c22e34507ff26124029c8f4289139bc598d62eb66"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 2: C Fundamentals"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example pun.c on Page 10"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def main():\n",
      "    print \"To C, or not to C: that is the question.\" #print statement demo\n",
      "if  __name__=='__main__':\n",
      "    main()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "To C, or not to C: that is the question.\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example on Page 14"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ways for printing on a single line\n",
      "print \"To C, or not to C: that is the question.\" \n",
      "print \"To C, or not to C:\",\n",
      "print \"that is the question.\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "To C, or not to C: that is the question.\n",
        "To C, or not to C: that is the question.\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example dweight.c on Page 20"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def main():\n",
      "    #variable declaration\n",
      "    height = 8 \n",
      "    length = 12\n",
      "    width =10\n",
      "    volume = height * length * width #volume calculation\n",
      "    weight = (volume + 165)/166 #weight calculation\n",
      "    \n",
      "    #print statements\n",
      "    print \"Dimensions: %dx%dx%d\" % (length,width,height) \n",
      "    print \"Volume (cubic inches): %d\" % volume\n",
      "    print \"Dimensional weight (pounds): %d\" % weight\n",
      "    \n",
      "if  __name__=='__main__':\n",
      "    main()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Dimensions: 12x10x8\n",
        "Volume (cubic inches): 960\n",
        "Dimensional weight (pounds): 6\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example dweight2.c on Page 23"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def main():\n",
      "    #input from user\n",
      "    height = int(raw_input(\"Enter height of box: \"))\n",
      "    length = int(raw_input(\"Enter length of box: \"))\n",
      "    width = int(raw_input(\"Enter width of box: \"))\n",
      "    volume = height * length * width #volume calculation\n",
      "    weight = (volume + 165)/166 #weight calculation\n",
      "    \n",
      "    #print statements\n",
      "    print \"Volume (cubic inches): %d\" % volume\n",
      "    print \"Dimensional weight (pounds): %d\" % weight\n",
      "    \n",
      "if  __name__=='__main__':\n",
      "    main()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter height of box: 8\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter length of box: 12\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter width of box: 10\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Volume (cubic inches): 960\n",
        "Dimensional weight (pounds): 6\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example celsius.c on Page 24"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def main():\n",
      "    #variable declaration\n",
      "    FREEZING_PT=32.0\n",
      "    SCALE_FACTOR= 5.02/9.0\n",
      "    \n",
      "    #input from user\n",
      "    farenheit=float(raw_input(\"Enter Farenheit temperature: \"))\n",
      "    celsius=(farenheit-FREEZING_PT) * SCALE_FACTOR #convert farenheit to celcius\n",
      "    print \"Celsius equivalent: %.1f\" % celsius\n",
      "if  __name__=='__main__':\n",
      "    main()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Farenheit temperature: 100\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Celsius equivalent: 37.9\n"
       ]
      }
     ],
     "prompt_number": 4
    }
   ],
   "metadata": {}
  }
 ]
}