summaryrefslogtreecommitdiff
path: root/A_First_course_in_Programming_with_C
diff options
context:
space:
mode:
authorhardythe12015-06-03 15:27:17 +0530
committerhardythe12015-06-03 15:27:17 +0530
commitdf60071cf1d1c18822d34f943ab8f412a8946b69 (patch)
treeab059cf19bad4a1233a464ccf5d72cf8b3fb323c /A_First_course_in_Programming_with_C
parentfba055ce5aa0955e22bac2413c33493b10ae6532 (diff)
downloadPython-Textbook-Companions-df60071cf1d1c18822d34f943ab8f412a8946b69.tar.gz
Python-Textbook-Companions-df60071cf1d1c18822d34f943ab8f412a8946b69.tar.bz2
Python-Textbook-Companions-df60071cf1d1c18822d34f943ab8f412a8946b69.zip
add books
Diffstat (limited to 'A_First_course_in_Programming_with_C')
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter10.ipynb1094
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter11.ipynb1098
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter12.ipynb1236
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter13.ipynb169
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter14.ipynb625
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter4.ipynb431
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter5.ipynb657
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter6.ipynb1304
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter7.ipynb1655
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter8.ipynb665
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter9.ipynb1638
-rwxr-xr-xA_First_course_in_Programming_with_C/screenshots/chapter14.pngbin0 -> 31008 bytes
-rwxr-xr-xA_First_course_in_Programming_with_C/screenshots/chapter5.pngbin0 -> 30662 bytes
-rwxr-xr-xA_First_course_in_Programming_with_C/screenshots/chapter9.pngbin0 -> 27119 bytes
14 files changed, 10572 insertions, 0 deletions
diff --git a/A_First_course_in_Programming_with_C/Chapter10.ipynb b/A_First_course_in_Programming_with_C/Chapter10.ipynb
new file mode 100755
index 00000000..6bb23256
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter10.ipynb
@@ -0,0 +1,1094 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 10: Structures and Unions<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 1, Page number: SAU - 5<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#student structure\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "class student:\n",
+ " rno = 0\n",
+ " sname = \"\"\n",
+ " tot = 0 \n",
+ " \n",
+ "x = student()\n",
+ "\n",
+ "x.rno = int(raw_input(\"\\nEnter roll number, name and total marks\"))\n",
+ "x.sname = raw_input(\"\")\n",
+ "x.tot = int(raw_input(\"\"))\n",
+ "\n",
+ "sys.stdout.write(\"\\n\\tDetails entered are \\n\")\n",
+ "sys.stdout.write(\"\\nRoll No. : %d\"%(x.rno))\n",
+ "sys.stdout.write(\"\\nStudent Name : %s\"%(x.sname))\n",
+ "sys.stdout.write(\"\\nTotal marks : %d\"%(x.tot))\n",
+ "sys.stdout.write(\"\\n\\nPress any key to continue...\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter roll number, name and total marks20147\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "PRADEEP\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "64\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\tDetails entered are \n",
+ "\n",
+ "Roll No. : 20147\n",
+ "Student Name : PRADEEP\n",
+ "Total marks : 64\n",
+ "\n",
+ "Press any key to continue..."
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2, Page number: SAU - 6<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import sys\n",
+ "\n",
+ "class student:\n",
+ " rno = 0 \n",
+ " sname = \"\"\n",
+ " tot = 0\n",
+ " \n",
+ "ch = 'y'\n",
+ "std = [student() for i in range(0,50)]\n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many students ? \"))\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " std[i].rno = int(raw_input(\"\\nRoll Number ? \"))\n",
+ " std[i].sname = raw_input(\"\\nName ? \")\n",
+ " std[i].tot = int(raw_input(\"\\nTotal marks ? \"))\n",
+ " \n",
+ "while ch == 'y' or ch == 'Y':\n",
+ " temp = int(raw_input(\"\\nEnter student roll number to display marks : \"))\n",
+ " flag = 0\n",
+ " for i in range(0,n):\n",
+ " if flag == 0:\n",
+ " if std[i].rno == temp:\n",
+ " sys.stdout.write(\"\\nMarks obtained by %d %s\"%(std[i].rno,std[i].sname))\n",
+ " sys.stdout.write(\"\\nTotal : %d\"%(std[i].tot))\n",
+ " flag = 1\n",
+ " \n",
+ " if flag == 0 :\n",
+ " sys.stdout.write(\"\\n%d is not present in the list\"%(temp))\n",
+ " ch = raw_input(\"\\npress y - to continue \\n any other key to stop.\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many students ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Roll Number ? 20201\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? ARUN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total marks ? 78\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Roll Number ? 20208\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? DEEPAK\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total marks ? 69\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Roll Number ? 20223\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? SUSMITHA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total marks ? 88\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter student roll number to display marks : 20208\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Marks obtained by 20208 DEEPAK\n",
+ "Total : 69"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "press y - to continue \n",
+ " any other key to stop.N\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 3, Page number: SAU - 8<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import sys\n",
+ "\n",
+ "class student:\n",
+ " rno = 0 \n",
+ " sname = \"\"\n",
+ " tot = 0\n",
+ " \n",
+ "std = [student() for i in range(0,50)]\n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many students ? \"))\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " std[i].rno = int(raw_input(\"\\nRoll Number ? \"))\n",
+ " std[i].sname = raw_input(\"\\nName ? \")\n",
+ " std[i].tot = int(raw_input(\"\\nTotal marks ? \"))\n",
+ " \n",
+ "print \"\\n-------------------------------------------------------\"\n",
+ "print \"\\n Roll No. Name Total Marks\"\n",
+ "print \"\\n-------------------------------------------------------\"\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " if std[i].tot >= 75:\n",
+ " sys.stdout.write(\"\\n %-8d %-20s %5d\"%(std[i].rno,std[i].sname,std[i].tot))\n",
+ " \n",
+ "print \"\\n-------------------------------------------------------\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many students ? 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Roll Number ? 30401\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? ANAND\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total marks ? 59\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Roll Number ? 30404\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? NIRMAL\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total marks ? 64\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Roll Number ? 30428\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? ISWARYA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total marks ? 82\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Roll Number ? 30432\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? VIVEKA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total marks ? 79\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ " Roll No. Name Total Marks\n",
+ "\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ " 30428 ISWARYA 82\n",
+ " 30432 VIVEKA 79\n",
+ "-------------------------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 4, Page number: SAU - 10<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import sys\n",
+ "\n",
+ "class employee:\n",
+ " eno = 0\n",
+ " ename = \"\"\n",
+ " epay = 0\n",
+ " jdate = \"\"\n",
+ " \n",
+ "def revise(temp):\n",
+ " if temp <= 2000:\n",
+ " return (temp + (temp*0.15))\n",
+ " else:\n",
+ " if temp <= 5000:\n",
+ " return (temp + (temp * 0.10))\n",
+ " else:\n",
+ " return temp\n",
+ " \n",
+ " \n",
+ "employs = [employee() for i in range(0,25)]\n",
+ "i = 0\n",
+ "ch = 'y'\n",
+ "\n",
+ "while ch.upper() == 'Y':\n",
+ " employs[i].eno = int(raw_input(\"\\nEmployee No.? \"))\n",
+ " employs[i].ename = raw_input(\"\\nName ? \")\n",
+ " employs[i].epay = int(raw_input(\"\\nExisting pay? \"))\n",
+ " employs[i].jdate = raw_input(\"\\nJoining Date ? \")\n",
+ " i += 1\n",
+ " ch = raw_input(\"\\nPress y - to continue any other key to stop.\")\n",
+ " \n",
+ "n = i\n",
+ "sys.stdout.write(\"\\n\\n%d records are entered\"%(n))\n",
+ "sys.stdout.write(\"\\nPress any key to print the revised salary list\")\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " employs[i].epay = revise(employs[i].epay)\n",
+ " \n",
+ "print \"\\n Employees Revised Pay List\"\n",
+ "print \"\\n----------------------------------------------------------------------------------\"\n",
+ "print \"\\n S.No Number Name Joinint date Pay\"\n",
+ "print \"\\n----------------------------------------------------------------------------------\"\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " sys.stdout.write(\"\\n %-4d %-d %-15s %10s %-8d\"%(i+1,employs[i].eno,employs[i].ename,employs[i].jdate,employs[i].epay))\n",
+ " \n",
+ "print \"\\n----------------------------------------------------------------------------------\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee No.? 20101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? ASHIKA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Existing pay? 1000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Joining Date ? 31/04/2001\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press y - to continue any other key to stop.Y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee No.? 20182\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? ASHWIN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Existing pay? 6000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Joining Date ? 11/12/1995\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press y - to continue any other key to stop.Y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee No.? 20204\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Name ? PRAVEEN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Existing pay? 3000\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Joining Date ? 18/06/1994\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press y - to continue any other key to stop.N\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "3 records are entered\n",
+ "Press any key to print the revised salary list\n",
+ " Employees Revised Pay List\n",
+ "\n",
+ "----------------------------------------------------------------------------------\n",
+ "\n",
+ " S.No Number Name Joinint date Pay\n",
+ "\n",
+ "----------------------------------------------------------------------------------\n",
+ "\n",
+ " 1 20101 ASHIKA 31/04/2001 1150 \n",
+ " 2 20182 ASHWIN 11/12/1995 6000 \n",
+ " 3 20204 PRAVEEN 18/06/1994 3300 \n",
+ "----------------------------------------------------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 5, Page number: SAU - 13<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import sys\n",
+ "\n",
+ "class cricket:\n",
+ " pname = \"\"\n",
+ " tname = \"\"\n",
+ " bavg = 0\n",
+ " \n",
+ "probable = [cricket() for i in range(0,30)]\n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many players ? \"))\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " probable[i].pname = raw_input(\"\\nPlayer name ? \")\n",
+ " probable[i].tname = raw_input(\"\\nWhich team ? \")\n",
+ " probable[i].bavg = int(raw_input(\"\\nBatting average ? \"))\n",
+ " \n",
+ "j = 0\n",
+ "teams = ['' for i in range(0,20)]\n",
+ "\n",
+ "teams[j] = probable[0].tname\n",
+ "j += 1\n",
+ "i = 1\n",
+ "\n",
+ "for i in range(1,n):\n",
+ " flag = 0\n",
+ " k = 0\n",
+ " while k < j and flag == 0: \n",
+ " if probable[i].tname == teams[k]:\n",
+ " flag = 1\n",
+ " k += 1\n",
+ " if flag == 0:\n",
+ " teams[j] = probable[i].tname\n",
+ " j += 1\n",
+ " i += 1\n",
+ "\n",
+ "for k in range(0,j):\n",
+ " sys.stdout.write(\"\\n\\t%s\"%(teams[k]))\n",
+ " print \"\\n-------------------------------------------------------\"\n",
+ " for i in range(0,n):\n",
+ " if probable[i].tname == teams[k]:\n",
+ " sys.stdout.write(\"\\n %-15s %6d\"%(probable[i].pname,probable[i].bavg))\n",
+ " print \"\\n-------------------------------------------------------\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many players ? 6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Player name ? KUMBLE\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Which team ? KARNATAKA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Batting average ? 22\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Player name ? KAMBLI\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Which team ? MUMBAI\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Batting average ? 39\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Player name ? SRIKANTH\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Which team ? TAMILNADU\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Batting average ? 52\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Player name ? SACHIN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Which team ? MUMBAI\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Batting average ? 69\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Player name ? RAHUL\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Which team ? KARNATAKA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Batting average ? 57\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Player name ? RAMESH\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Which team ? TAMILNADU\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Batting average ? 48\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\tKARNATAKA\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ " KUMBLE 22\n",
+ " RAHUL 57\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ "\tMUMBAI\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ " KAMBLI 39\n",
+ " SACHIN 69\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ "\tTAMILNADU\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ " SRIKANTH 52\n",
+ " RAMESH 48\n",
+ "-------------------------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 6, Page number: SAU - 19<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import sys\n",
+ "\n",
+ "class student:\n",
+ " roll_no = 0\n",
+ " sname = \"\"\n",
+ " marks = 0 \n",
+ " \n",
+ "std = [student() for i in range(0,10)]\n",
+ "\n",
+ "print \"\\n-----------------------------------------------------------------------\"\n",
+ "print \"\\n Main Menu\"\n",
+ "print \"\\n-----------------------------------------------------------------------\"\n",
+ "print \"\\nPress 1 to enter roll numbers\"\n",
+ "print \"\\n 2 to enter names\"\n",
+ "print \"\\n 3 to enter marks\"\n",
+ "print \"\\n 4 to stop\"\n",
+ "ch = int(raw_input(\"\\nEnter your choice : \"))\n",
+ "if ch < 4:\n",
+ " n = int(raw_input(\"How many students ? \"))\n",
+ "\n",
+ " for i in range(0,n):\n",
+ " if ch == 1:\n",
+ " std[i].roll_no = int(raw_input(\"\\nRoll number ? \"))\n",
+ " else:\n",
+ " if ch == 2:\n",
+ " std[i].sname = raw_input(\"\\nStudent name ? \")\n",
+ " else:\n",
+ " if ch == 3:\n",
+ " std[i].marks = int(raw_input(\"\\nAverage marks ? \"))\n",
+ " \n",
+ " if ch == 1:\n",
+ " print \"\\n-------------------------------------------------------------------\"\n",
+ " print \"\\n Students roll number list\"\n",
+ " print \"\\n-------------------------------------------------------------------\"\n",
+ " for i in range(0,n):\n",
+ " sys.stdout.write(\"\\n\\t%d\"%(std[i].roll_no))\n",
+ " print \"\\n-------------------------------------------------------------------\"\n",
+ " else:\n",
+ " if ch == 2:\n",
+ " print \"\\n-------------------------------------------------------------------\"\n",
+ " print \"\\n Students name list\"\n",
+ " print \"\\n-------------------------------------------------------------------\"\n",
+ " for i in range(0,n):\n",
+ " sys.stdout.write(\"\\n\\t%s\"%(std[i].sname))\n",
+ " print \"\\n-------------------------------------------------------------------\"\n",
+ " else:\n",
+ " if ch == 3:\n",
+ " print \"\\n-------------------------------------------------------------------\"\n",
+ " print \"\\n Students mark list\"\n",
+ " print \"\\n-------------------------------------------------------------------\"\n",
+ " for i in range(0,n):\n",
+ " sys.stdout.write(\"\\n\\t%d\"%(std[i].marks))\n",
+ " print \"\\n-------------------------------------------------------------------\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "-----------------------------------------------------------------------\n",
+ "\n",
+ " Main Menu\n",
+ "\n",
+ "-----------------------------------------------------------------------\n",
+ "\n",
+ "Press 1 to enter roll numbers\n",
+ "\n",
+ " 2 to enter names\n",
+ "\n",
+ " 3 to enter marks\n",
+ "\n",
+ " 4 to stop\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter your choice : 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many students ? 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student name ? AJITH\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student name ? RAJU\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student name ? VIGNESH\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student name ? DIVYA\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "-------------------------------------------------------------------\n",
+ "\n",
+ " Students name list\n",
+ "\n",
+ "-------------------------------------------------------------------\n",
+ "\n",
+ "\tAJITH\n",
+ "\tRAJU\n",
+ "\tVIGNESH\n",
+ "\tDIVYA\n",
+ "-------------------------------------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter11.ipynb b/A_First_course_in_Programming_with_C/Chapter11.ipynb
new file mode 100755
index 00000000..b51ed5ad
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter11.ipynb
@@ -0,0 +1,1098 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 11: Pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number : PTR-5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a = int(raw_input(\"\\nEnter two integers : \"))\n",
+ "b = int(raw_input(\"\"))\n",
+ "\n",
+ "xptr = id(a)\n",
+ "yptr = id(b)\n",
+ "\n",
+ "#There is no pointer concept in python\n",
+ "s = a + b\n",
+ "\n",
+ "print \"\\nSum = \",s"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter two integers : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum = 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number : PTR-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "a = int(raw_input(\"\\nEnter two integers : \"))\n",
+ "b = int(raw_input(\"\"))\n",
+ "\n",
+ "xptr = id(a)\n",
+ "yptr = id(b)\n",
+ "\n",
+ "#There is no pointer concept in python\n",
+ "if a > b:\n",
+ " big = a\n",
+ "else:\n",
+ " big = b\n",
+ " \n",
+ "print \"\\nBiggest number is \",big"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter two integers : 15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Biggest number is 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, Page Number : PTR-7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def add10(x,y):\n",
+ " #There is no pointer concept in python\n",
+ " x = x + 10\n",
+ " y = y + 10\n",
+ " print \"\\n\\nInside the function a = \",x,\" b = \",y\n",
+ " return x,y\n",
+ " \n",
+ "a = 25\n",
+ "b = 10\n",
+ "\n",
+ "print \"\\nBefore function call a = \",a,\" b = \",b\n",
+ "a,b = add10(a,b)\n",
+ "print \"\\nAfter function call a = \",a,\" b = \",b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Before function call a = 25 b = 10\n",
+ "\n",
+ "\n",
+ "Inside the function a = 35 b = 20\n",
+ "\n",
+ "After function call a = 35 b = 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, Page Number : PTR-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def swap(x,y):\n",
+ " #There is no pointer concept in python\n",
+ " temp = x\n",
+ " x = y\n",
+ " y = temp\n",
+ " return x,y\n",
+ "\n",
+ "a = int(raw_input(\"\\nEnter two integers : \"))\n",
+ "b = int(raw_input(\"\"))\n",
+ "\n",
+ "print \"\\nBefore function call a = \",a,\" b = \",b\n",
+ "\n",
+ "a,b = swap(a,b)\n",
+ "\n",
+ "print \"\\n\\nAfter function call, values are exchanged as \\n a = \",a,\" b = \",b"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter two integers : 25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Before function call a = 25 b = 500\n",
+ "\n",
+ "\n",
+ "After function call, values are exchanged as \n",
+ " a = 500 b = 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, Page Number : PTR-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "x = [0.0 for i in range(0,10)]\n",
+ "n = int(raw_input(\"\\nHow many values ? \"))\n",
+ "\n",
+ "print \"\\nEnter all values in the list\\n\"\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " x[i] = float(raw_input(\"\"))\n",
+ "\n",
+ "sum1 = 0.0\n",
+ "#Since sum is a predefined function in python, sum1 is used\n",
+ "for i in range(0,n):\n",
+ " sum1 = sum1 + x[i]\n",
+ " #There is no pointer concept in python\n",
+ " \n",
+ "mean = sum1/n\n",
+ "\n",
+ "sys.stdout.write(\"\\nArithmetic mean = %0.3f\"%(mean))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many values ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all values in the list\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.48\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.54\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.26\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2.98\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Arithmetic mean = 3.315"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, Page Number : PTR-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "xp = [0 for i in range(0,10)]\n",
+ "n = int(raw_input(\"\\nHow many values ? \"))\n",
+ "\n",
+ "#There is no pointer concept in python\n",
+ "print \"\\nEnter all values\\n\"\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " xp[i] = int(raw_input(\"\"))\n",
+ "\n",
+ "print \"\\nThe reversed list is\\n\"\n",
+ "for i in range(n-1,0-1,-1):\n",
+ " sys.stdout.write(\"%6d\"%(xp[i]))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many values ? 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "11\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "13\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "14\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "16\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The reversed list is\n",
+ "\n",
+ " 16 15 14 13 12 11"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, Page Number : PTR-21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "a = [[0 for i in range(0,10)]for i in range(0,10)]\n",
+ "b = [[0 for i in range(0,10)]for i in range(0,10)]\n",
+ "\n",
+ "c = [[0 for i in range(0,5)]for i in range(0,5)]\n",
+ "m = int(raw_input(\"\\nFor A matrix \\nHow many rows and columns ? \"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "print \"\\nEnter A matrix values\\n\"\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ " \n",
+ "n = int(raw_input(\"\\nFor B matrix\\nHow many rows and columns ? \"))\n",
+ "l = int(raw_input(\"\"))\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " for j in range(0,l):\n",
+ " b[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,l):\n",
+ " c[i][j] = 0\n",
+ " for k in range(0,l):\n",
+ " c[i][j] = c[i][j] + (a[i][k] * b[k][j])\n",
+ " \n",
+ "print \"\\nResultant matrix is \\n\"\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,l):\n",
+ " sys.stdout.write(\"%6d\"%(c[i][j]))\n",
+ " sys.stdout.write(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "For A matrix \n",
+ "How many rows and columns ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter A matrix values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "For B matrix\n",
+ "How many rows and columns ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Resultant matrix is \n",
+ "\n",
+ " 26 9 5\n",
+ " 4 -28 18\n",
+ " 18 19 -3\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, Page Number : PTR-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "count = 0\n",
+ "\n",
+ "st = raw_input(\"\\nEnter a string : \")\n",
+ "sptr = st\n",
+ "i = 0\n",
+ "\n",
+ "while i < len(st):\n",
+ " if st[i].upper() == 'A' or st[i].upper() == 'E' or st[i].upper() == 'I' or st[i].upper() == 'O' or st[i].upper() == 'U':\n",
+ " count = count + 1\n",
+ " i = i + 1\n",
+ " \n",
+ "print \"\\nNumber of vowels = \",count"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter a string : GOOD LUCK to all\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Number of vowels = 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9, Page Number : PTR-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def sort_names(sn,n):\n",
+ " for i in range(0,n):\n",
+ " for j in range(i+1,n):\n",
+ " if sn[i] > sn[j]:\n",
+ " temp = sn[i]\n",
+ " sn[i] = sn[j]\n",
+ " sn[j] = temp\n",
+ " \n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many names ?\"))\n",
+ "\n",
+ "snames = [\"\" for i in range(0,10)]\n",
+ "\n",
+ "print \"\\nEnter all names \\n\"\n",
+ "for i in range(0,n):\n",
+ " snames[i] = raw_input(\"\")\n",
+ " \n",
+ "sort_names(snames,n)\n",
+ "\n",
+ "print \"\\nThe name list in alphabetical order\"\n",
+ "for i in range(0,n):\n",
+ " print snames[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many names ?4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all names \n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "DEEPAK\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SHERIN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SONIKA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ARUN\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The name list in alphabetical order\n",
+ "ARUN\n",
+ "DEEPAK\n",
+ "SHERIN\n",
+ "SONIKA\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10, Page Number : PTR-27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"\\nEnter a string : \"\n",
+ "st = raw_input(\"\")\n",
+ "rst = ['' for i in range(0,80)]\n",
+ "\n",
+ "rst = st[::-1]\n",
+ " \n",
+ "if st == rst:\n",
+ " print st,\" is a palindrome string\"\n",
+ "else:\n",
+ " print st,\" is not a palindrome string\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter a string : \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "LIRIL\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "LIRIL is a palindrome string\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11, Page Number : PTR-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "print \"\\nEnter a string : \"\n",
+ "st = raw_input(\"\")\n",
+ "\n",
+ "#There is no pointer concept in python\n",
+ "city = st\n",
+ "\n",
+ "print \"\\nThe copied string : \",city"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter a string : \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "NEW DELHI\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The copied string : NEW DELHI\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12, Page Number : PTR-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#class is used instead of structure in python\n",
+ "\n",
+ "class student():\n",
+ " rno = 0\n",
+ " sname = ''\n",
+ " tot = 0\n",
+ "\n",
+ "sptr = student()\n",
+ "sptr.rno = int(raw_input(\"\\nEnter register No.:\"))\n",
+ "sptr.sname = raw_input(\"\\nEnter student name : \")\n",
+ "sptr.tot = int(raw_input(\"\\nEnter total marks : \"))\n",
+ "\n",
+ "print \"\\n\\tDetails entered are \\n\"\n",
+ "print \"\\nReg.No, : \",sptr.rno\n",
+ "print \"\\nName : \",sptr.sname\n",
+ "print \"\\nTotal : \",sptr.tot\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter register No.:101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter student name : Ashwin\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter total marks : 89\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\tDetails entered are \n",
+ "\n",
+ "\n",
+ "Reg.No, : 101\n",
+ "\n",
+ "Name : Ashwin\n",
+ "\n",
+ "Total : 89\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13, Page Number : PTR-32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#There is no pointer concept in python\n",
+ "def add(x,y):\n",
+ " return x+y\n",
+ "\n",
+ "def multiply(x,y):\n",
+ " return x*y\n",
+ "\n",
+ "a = int(raw_input(\"\\nEnter two integers : \"))\n",
+ "b = int(raw_input(\"\"))\n",
+ "\n",
+ "sum1 = add(a,b)\n",
+ "\n",
+ "print \"Sum a + b = \",sum1\n",
+ "\n",
+ "product = multiply(a,b)\n",
+ "print \"\\nProduct a * b = \",product"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter two integers : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Sum a + b = 8\n",
+ "\n",
+ "Product a * b = 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter12.ipynb b/A_First_course_in_Programming_with_C/Chapter12.ipynb
new file mode 100755
index 00000000..1f9a4a84
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter12.ipynb
@@ -0,0 +1,1236 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 12: Files"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number : FLS-7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"SAMPLE.TXT\",\"w\")\n",
+ "\n",
+ "print \"\\nType the text press enter key at end.\\n\\n\"\n",
+ "\n",
+ "ch = raw_input(\"\")\n",
+ "fp.write(ch)\n",
+ "\n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Type the text press enter key at end.\n",
+ "\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Computer Programming in C language is widely used for Science and Engineering applications.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number : FLS-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "count = 0 \n",
+ "\n",
+ "fp = open(\"SAMPLE.TXT\",\"r\")\n",
+ "\n",
+ "print \"\\nThe content of the text file is : \\n\\n\"\n",
+ "\n",
+ "ch = fp.read()\n",
+ "\n",
+ "for i in ch:\n",
+ " sys.stdout.write(\"%c\"%(i))\n",
+ " if i.upper() == 'A' or i.upper() == 'E' or i.upper() == 'I' or i.upper() == 'O' or i.upper() == 'U':\n",
+ " count = count + 1\n",
+ " \n",
+ "print \"\\nNumber of vowels present = \",count\n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The content of the text file is : \n",
+ "\n",
+ "\n",
+ "Computer Programming in C language is widely used for Science and Engineering applications.\n",
+ "Number of vowels present = 31\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, Page Number : FLS-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fp = open(\"STUDENT.DAT\",\"w\")\n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many students ? \"))\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " rno = int(raw_input(\"\\nStudent roll no., name, total ? \"))\n",
+ " sname = raw_input(\"\")\n",
+ " tot = int(raw_input(\"\"))\n",
+ " fp.write(\"%d %s %d\\n\"%(rno,sname,tot))\n",
+ " \n",
+ "fp.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many students ? 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student roll no., name, total ? 101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ARUN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "78\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student roll no., name, total ? 102\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "DEEPAK\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "72\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student roll no., name, total ? 103\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SUSHMITHA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "86\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, Page Number : FLS-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "fptr = open(\"STUDENT.DAT\",\"r\")\n",
+ "\n",
+ "print \"\\n--------------------------------------------------------\"\n",
+ "print \"\\n Roll No Name Total \"\n",
+ "print \"\\n--------------------------------------------------------\"\n",
+ "\n",
+ "rno = 0\n",
+ "sname = ''\n",
+ "tot = 0\n",
+ "\n",
+ "lines = fptr.readlines()\n",
+ "\n",
+ "for line in lines:\n",
+ " rno,sname,tot = line.split(' ')\n",
+ " tot = int(tot)\n",
+ " if tot >= 75:\n",
+ " print \"\\n \",rno,\"\\t\",sname,\"\\t\\t\",tot\n",
+ " \n",
+ "print \"\\n--------------------------------------------------------\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "--------------------------------------------------------\n",
+ "\n",
+ " Roll No Name Total \n",
+ "\n",
+ "--------------------------------------------------------\n",
+ "\n",
+ " 101 \tARUN \t\t78\n",
+ "\n",
+ " 103 \tSUSHMITHA \t\t86\n",
+ "\n",
+ "--------------------------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, Page Number : FLS-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ch = 'y'\n",
+ "\n",
+ "fp = open(\"STUDENT.DAT\",\"a\")\n",
+ "\n",
+ "while ch.upper() == 'Y':\n",
+ " rno = int(raw_input(\"\\nStudent roll no., name, total ? \"))\n",
+ " sname = raw_input(\"\")\n",
+ " tot = int(raw_input(\"\"))\n",
+ " fp.write(\"%d %s %d\\n\"%(rno,sname,tot))\n",
+ " print \"\\nPress y - to add more records\"\n",
+ " print \"\\n any other key to stop.\"\n",
+ " ch = raw_input(\"\")\n",
+ " \n",
+ "print \"\\n-------------------------------------------------------\"\n",
+ "print \"\\n Roll No. Name Total\"\n",
+ "print \"\\n-------------------------------------------------------\"\n",
+ "\n",
+ "rno = 0\n",
+ "sname = ''\n",
+ "tot = 0\n",
+ "\n",
+ "fp.close()\n",
+ "fp = open(\"STUDENT.DAT\",\"r\")\n",
+ "\n",
+ "lines = fp.readlines()\n",
+ "\n",
+ "for line in lines:\n",
+ " rno,sname,tot = line.split(' ')\n",
+ " print \"\\n \",rno,\"\\t\\t\",sname,\"\\t\\t\",tot\n",
+ " \n",
+ "print \"\\n--------------------------------------------------------\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Student roll no., name, total ? 104\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "RAHUL\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "67\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press y - to add more records\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "N\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ " Roll No. Name Total\n",
+ "\n",
+ "-------------------------------------------------------\n",
+ "\n",
+ " 101 \t\tARUN \t\t78\n",
+ "\n",
+ "\n",
+ " 102 \t\tDEEPAK \t\t72\n",
+ "\n",
+ "\n",
+ " 103 \t\tSUSHMITHA \t\t86\n",
+ "\n",
+ "\n",
+ " 104 \t\tRAHUL \t\t67\n",
+ "\n",
+ "\n",
+ "--------------------------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, Page Number : FLS-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "source_name = raw_input(\"\\nEnter the source file name : \")\n",
+ "\n",
+ "source_fptr = open(source_name,\"r\")\n",
+ "\n",
+ "target_name = raw_input(\"\\nEnter the target file name : \")\n",
+ "target_fptr = open(target_name,\"w+\")\n",
+ "\n",
+ "if source_fptr == 0:\n",
+ " print \"\\nNo content/source file !!!\"\n",
+ " print \"\\n press any key...\"\n",
+ "else:\n",
+ " while True:\n",
+ " ch = source_fptr.read(1)\n",
+ " if not ch:\n",
+ " break\n",
+ " target_fptr.write(\"%c\"%(ch))\n",
+ " \n",
+ "target_fptr.close()\n",
+ "target_fptr = open(target_name,\"r\")\n",
+ "\n",
+ "print \"\\nThe contents of the target file are\"\n",
+ "print \"\\n---------------------------------------\\n\"\n",
+ "lines = target_fptr.readlines()\n",
+ "\n",
+ "for line in lines:\n",
+ " print line\n",
+ " \n",
+ "target_fptr.close()\n",
+ "source_fptr.close()\n",
+ "print \"\\n\\n Press any key...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the source file name : SAMPLE.TXT\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the target file name : SAMPLE.BAK\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The contents of the target file are\n",
+ "\n",
+ "---------------------------------------\n",
+ "\n",
+ "Computer Programming in C language is widely used for Science and Engineering applications.\n",
+ "\n",
+ "\n",
+ " Press any key...\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, Page Number : FLS-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ch = 'y'\n",
+ "\n",
+ "while ch == 'y' or ch == 'Y':\n",
+ " print \"\\n\\t MENU\"\n",
+ " print \"\\n\\t-------------------------------------------\"\n",
+ " print \"\\n\\tPress 1 to create data file\"\n",
+ " print \"\\n\\t 2 to find smallest & largest integer\"\n",
+ " \n",
+ " choice = int(raw_input(\"\\n\\n\\tEnter your choice : \"))\n",
+ " \n",
+ " if choice == 1:\n",
+ " data_file = open(\"DATAFILE\",\"w\")\n",
+ " n = int(raw_input(\"\\nEnter data, enter 0 at end of reading\\n\"))\n",
+ " while n != 0:\n",
+ " data_file.write(\"%d\\n\"%(n))\n",
+ " n = int(raw_input(\"\"))\n",
+ " data_file.close()\n",
+ " else:\n",
+ " if choice == 2:\n",
+ " data_file = open(\"DATAFILE\",\"r\")\n",
+ " n1 = data_file.readlines()\n",
+ " n = n1[0]\n",
+ " big = n\n",
+ " small = n\n",
+ " for n in n1:\n",
+ " if n > big:\n",
+ " big = n \n",
+ " if n < small:\n",
+ " small = n\n",
+ " \n",
+ " data_file.close()\n",
+ " print \"\\nLargest integer is \",big\n",
+ " print \"\\nSmallest integer is \",small\n",
+ " else:\n",
+ " print \"\\nWrong choice !!!\" \n",
+ " ch = raw_input(\"\\n\\nPress Y to continue, any other key to stop...\")\n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\t MENU\n",
+ "\n",
+ "\t-------------------------------------------\n",
+ "\n",
+ "\tPress 1 to create data file\n",
+ "\n",
+ "\t 2 to find smallest & largest integer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "\tEnter your choice : 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter data, enter 0 at end of reading\n",
+ "23\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "76\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-56\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "876\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "52\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Press Y to continue, any other key to stop...y\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\t MENU\n",
+ "\n",
+ "\t-------------------------------------------\n",
+ "\n",
+ "\tPress 1 to create data file\n",
+ "\n",
+ "\t 2 to find smallest & largest integer\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "\tEnter your choice : 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Largest integer is 876\n",
+ "\n",
+ "\n",
+ "Smallest integer is -56\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Press Y to continue, any other key to stop...n\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, Page Number : FLS-20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import os\n",
+ "\n",
+ "class emp_record:\n",
+ " eno = 0\n",
+ " ename = ''\n",
+ " bpay = 0.0\n",
+ " \n",
+ "erec = emp_record()\n",
+ "\n",
+ "def creatfile():\n",
+ " choice = 'y'\n",
+ " efile = open(\"EMPLOY.DAT\",\"w\")\n",
+ " while choice.upper() == 'Y':\n",
+ " erec.eno = int(raw_input(\"\\nEnter the employee No.\"))\n",
+ " erec.ename = raw_input(\"\\nEmployee Name ?\")\n",
+ " erec.bpay = float(raw_input(\"\\nBasic pay ?\"))\n",
+ " efile.write(\"%d %s %f\\n\"%(erec.eno,erec.ename,erec.bpay))\n",
+ " print \"\\n Press Y - to continue\"\n",
+ " print \"\\n any other key to stop.\"\n",
+ " choice = raw_input(\"\")\n",
+ " efile.close()\n",
+ " \n",
+ "def readfile():\n",
+ " eno = 0\n",
+ " ename = ''\n",
+ " bpay = 0.0\n",
+ " efile = open(\"EMPLOY.DAT\",\"r\")\n",
+ " print \"\\n----------------------------------------------------\"\n",
+ " print \"\\n Emp.No. Employee Name Basic pay\"\n",
+ " print \"\\n----------------------------------------------------\"\n",
+ " lines = efile.readlines()\n",
+ " \n",
+ " for line in lines:\n",
+ " eno,ename,bpay = line.split(' ')\n",
+ " print \"\\n\",eno,\"\\t\",ename,\"\\t\",bpay\n",
+ " print \"\\n----------------------------------------------------\"\n",
+ "\n",
+ "def appendrec():\n",
+ " choice = 'y'\n",
+ " efile = open(\"EMPLOY.DAT\",\"a\")\n",
+ " while choice.upper() == 'Y':\n",
+ " erec.eno = int(raw_input(\"\\nEnter the employee No. \"))\n",
+ " erec.ename = raw_input(\"\\nEmployee Name ? \")\n",
+ " erec.bpay = float(raw_input(\"\\nBasic pay ?\"))\n",
+ " efile.write(\"%d %s %f\\n\"%(erec.eno,erec.ename,erec.bpay))\n",
+ " print \"\\nPress Y - to continue\"\n",
+ " print \"\\n any other key to stop.\"\n",
+ " choice = raw_input(\"\")\n",
+ " efile.close()\n",
+ " \n",
+ "def modirec():\n",
+ " flag = 0\n",
+ " eno = 0\n",
+ " ename = ''\n",
+ " bpay = 0.0\n",
+ " efile = open(\"EMPLOY.DAT\",\"r+\")\n",
+ " print \"\\nTo modify a record \"\n",
+ " print \"\\n------------------\"\n",
+ " temp = int(raw_input(\"\\nEnter the Roll No.\"))\n",
+ " lines = efile.readlines()\n",
+ " for line in lines:\n",
+ " #while True and flag == 0:\n",
+ " eno,ename,bpay = line.split(' ')\n",
+ " if eno == temp:\n",
+ " print \"\\nExisting record details\"\n",
+ " print \"\\n\",eno,\"\\t\",ename,\"\\t\",bpay\n",
+ " print \"\\n\\nEnter the modified details\"\n",
+ " print \"\\n------------------------------\"\n",
+ " erec.eno = int(raw_input(\"\\nEnter the employee No. \"))\n",
+ " erec.ename = raw_input(\"\\nEmployee Name ? \")\n",
+ " erec.bpay = float(raw_input(\"\\nBasic pay ?\"))\n",
+ " efile.write(\"%d %s %f\\n\"%(erec.eno,erec.ename,erec.bpay))\n",
+ " flag = 1\n",
+ " print \"\\nThe record has been modified!\"\n",
+ " efile.close()\n",
+ " if flag == 0:\n",
+ " print \"\\nThe given record is not present in the file!!!\"\n",
+ " print \"\\nPress any key to continue ...\"\n",
+ " \n",
+ "def deleterec():\n",
+ " flag = 0\n",
+ " eno = 0\n",
+ " ename = ''\n",
+ " bpay = 0.0\n",
+ " efile = open(\"EMPLOY.DAT\",\"r\")\n",
+ " tfile = open(\"TEMP.DAT\",\"w\")\n",
+ " print \"\\nTo delete a record\"\n",
+ " print \"\\n------------------\"\n",
+ " temp = int(raw_input(\"\\nEnter the Roll No.\"))\n",
+ " while True:\n",
+ " eno,ename,bpay = efile.readline().split(' ')\n",
+ " if eno == temp:\n",
+ " print \"\\nExisting record details\"\n",
+ " print \"\\n\",eno,\"\\t\",ename,\"\\t\",bpay\n",
+ " print \"\\n is deleted!!!\"\n",
+ " flag = 1\n",
+ " tfile.write(\"%d %s %f\\n\"%(eno,ename,bpay))\n",
+ " tfile.close()\n",
+ " efile.close()\n",
+ " os.remove(\"EMPLOY.DAT\")\n",
+ " os.rename(\"TEMP.DAT\",\"EMPLOY.DAT\")\n",
+ " if flag == 0:\n",
+ " print \"\\nThe given record is not present in the file!!!\"\n",
+ " print \"\\n\\tpress any key to continue...\"\n",
+ " \n",
+ "n = 0\n",
+ "while n != 6:\n",
+ " print \"\\n\\tMain Menu\"\n",
+ " print \"\\n\\t Press 1 - file creation\"\n",
+ " print \"\\n\\t 2 - reading\"\n",
+ " print \"\\n\\t 3 - appending\"\n",
+ " print \"\\n\\t 4 - modify a record\"\n",
+ " print \"\\n\\t 5 - delete a record\"\n",
+ " print \"\\n\\t 6 - quit\"\n",
+ " n = int(raw_input(\"\\n\\nEnter your choice : \"))\n",
+ " \n",
+ " if n == 1:\n",
+ " creatfile()\n",
+ " else:\n",
+ " if n == 2:\n",
+ " readfile()\n",
+ " else:\n",
+ " if n == 3:\n",
+ " appendrec()\n",
+ " else:\n",
+ " if n == 4:\n",
+ " modirec()\n",
+ " else:\n",
+ " if n == 5:\n",
+ " deleterec()\n",
+ " \n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the employee No.2101\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee Name ?ARUN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Basic pay ?8500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Press Y - to continue\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the employee No.2102\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee Name ?DEEPAK\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Basic pay ?8000\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Press Y - to continue\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "N\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "----------------------------------------------------\n",
+ "\n",
+ " Emp.No. Employee Name Basic pay\n",
+ "\n",
+ "----------------------------------------------------\n",
+ "\n",
+ "2101 \tARUN \t8500.000000\n",
+ "\n",
+ "\n",
+ "2102 \tDEEPAK \t8000.000000\n",
+ "\n",
+ "\n",
+ "----------------------------------------------------\n",
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the employee No. 2103\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee Name ? SUSHMITHA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Basic pay ?6400\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press Y - to continue\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Y\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the employee No. 2104\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Employee Name ? ASHIKA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Basic pay ?6200\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Press Y - to continue\n",
+ "\n",
+ " any other key to stop.\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "N\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "To modify a record \n",
+ "\n",
+ "------------------\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the Roll No.2101\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The given record is not present in the file!!!\n",
+ "\n",
+ "Press any key to continue ...\n",
+ "\n",
+ "\tMain Menu\n",
+ "\n",
+ "\t Press 1 - file creation\n",
+ "\n",
+ "\t 2 - reading\n",
+ "\n",
+ "\t 3 - appending\n",
+ "\n",
+ "\t 4 - modify a record\n",
+ "\n",
+ "\t 5 - delete a record\n",
+ "\n",
+ "\t 6 - quit\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Enter your choice : 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "To delete a record\n",
+ "\n",
+ "------------------\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the Roll No.2102\n"
+ ]
+ },
+ {
+ "ename": "ValueError",
+ "evalue": "need more than 1 value to unpack",
+ "output_type": "pyerr",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
+ "\u001b[1;32m<ipython-input-1-5b4dfc956b00>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 128\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 129\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 130\u001b[1;33m \u001b[0mdeleterec\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 131\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 132\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;32m<ipython-input-1-5b4dfc956b00>\u001b[0m in \u001b[0;36mdeleterec\u001b[1;34m()\u001b[0m\n\u001b[0;32m 89\u001b[0m \u001b[0mtemp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mraw_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"\\nEnter the Roll No.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 90\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[0mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 91\u001b[1;33m \u001b[0meno\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mename\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mbpay\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mefile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m' '\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 92\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0meno\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mtemp\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 93\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"\\nExisting record details\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
+ "\u001b[1;31mValueError\u001b[0m: need more than 1 value to unpack"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter13.ipynb b/A_First_course_in_Programming_with_C/Chapter13.ipynb
new file mode 100755
index 00000000..84f2242b
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter13.ipynb
@@ -0,0 +1,169 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: C Preprocessor and Command Line Arguments"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number : PCL-3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def BIG(a,b):\n",
+ " if a > b:\n",
+ " return a\n",
+ " else:\n",
+ " return b\n",
+ " \n",
+ "def WAITMSG():\n",
+ " return \"\\nPress any key to continue...\"\n",
+ " \n",
+ "x = int(raw_input(\"\\nEnter two integers : \"))\n",
+ "y = int(raw_input(\"\"))\n",
+ "\n",
+ "print \"\\nBiggest integer is \",BIG(x,y),WAITMSG()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter two integers : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Biggest integer is 8 \n",
+ "Press any key to continue...\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number : PCL-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import time\n",
+ "\n",
+ "argv1 = \"SAMPLE.TXT\"\n",
+ "argv2 = \"SAMPLE.BAK\"\n",
+ "\n",
+ "source_fptr = open(\"SAMPLE.TXT\",\"r\")\n",
+ "target_fptr = open(\"SAMPLE.BAK\",\"w+\")\n",
+ "\n",
+ "if source_fptr == 0:\n",
+ " print \"\\nNo content/source file!!!\"\n",
+ " print \"\\n press any key to continue...\"\n",
+ "else:\n",
+ " print \"\\nCopying source file \",argv1,\" to target file \",argv2\n",
+ " print \"\\n please wait.\"\n",
+ " print \".\"\n",
+ " print \".\"\n",
+ " print \".\"\n",
+ " print \".\"\n",
+ "\n",
+ " if target_fptr == 0:\n",
+ " print \"\\nNo content/target file!!!\"\n",
+ " print \"\\n\\n Press any key to continue...\"\n",
+ " else:\n",
+ " while True:\n",
+ " ch = source_fptr.read(1)\n",
+ " if not ch:\n",
+ " break\n",
+ " target_fptr.write(\"%c\"%(ch))\n",
+ " print \"\\n\\nCopy completed, the target file contents\"\n",
+ " print \"\\n----------------------------------------\\n\"\n",
+ " target_fptr.close()\n",
+ " target_fptr = open(\"SAMPLE.BAK\",\"r\")\n",
+ " ch = target_fptr.readlines()\n",
+ " for line in ch:\n",
+ " print line\n",
+ " source_fptr.close()\n",
+ " target_fptr.close()\n",
+ " print \"\\n\\n press any key to continue...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Copying source file SAMPLE.TXT to target file SAMPLE.BAK\n",
+ "\n",
+ " please wait.\n",
+ ".\n",
+ ".\n",
+ ".\n",
+ ".\n",
+ "\n",
+ "\n",
+ "Copy completed, the target file contents\n",
+ "\n",
+ "----------------------------------------\n",
+ "\n",
+ "Computer Programming in C language is widely used for Science and Engineering applications.\n",
+ "\n",
+ "\n",
+ " press any key to continue...\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter14.ipynb b/A_First_course_in_Programming_with_C/Chapter14.ipynb
new file mode 100755
index 00000000..e1fefdcb
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter14.ipynb
@@ -0,0 +1,625 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 14: Graphics Using C"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number : GUC-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "a = int(raw_input(\"Enter the first number : \"))\n",
+ "b = int(raw_input(\"Enter the second number : \"))\n",
+ "\n",
+ "if a > b:\n",
+ " print a, \" IS THE BIGGEST NUMBER\"\n",
+ "else:\n",
+ " print b, \" IS THE BIGGEST NUMBER\"\n",
+ " \n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the first number : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the second number : 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5 IS THE BIGGEST NUMBER\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number : GUC-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "%pylab inline\n",
+ "import pylab\n",
+ "import matplotlib.pyplot as plt\n",
+ "\n",
+ "x1 = int(raw_input(\"Enter start point coordinate : \"))\n",
+ "y1 = int(raw_input())\n",
+ "\n",
+ "x2 = int(raw_input(\"Enter end point coordinate : \"))\n",
+ "y2 = int(raw_input())\n",
+ "\n",
+ "figure()\n",
+ "pylab.plot([x1,y1],[x2,y2])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "WARNING: pylab import has clobbered these variables: ['pylab']\n",
+ "`%pylab --no-import-all` prevents importing * from pylab and numpy\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Populating the interactive namespace from numpy and matplotlib\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter start point coordinate : 50\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "40\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter end point coordinate : 200\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "180\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 11,
+ "text": [
+ "[<matplotlib.lines.Line2D at 0x82b1130>]"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEACAYAAAC57G0KAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFM9JREFUeJzt3X9M1OcBx/HPETCx0Q6STWyB9VIR9RTW65TWRrIjE7ss\nk2hJSHCzVOg/2qzZOrW1fzh/bTCdLnXBTZdiuuyPtqaJmG5a29FD17TDpcY6SSZtIUOsRKa2sC26\nybM/nOehB8edd/f99X4ll9Dv/fg+PG0f3zx3X/QZY4wAAK6TZfUAAADpwQIPAC7FAg8ALsUCDwAu\nxQIPAC7FAg8ALjXuAt/X16fKykrNnTtX8+bN0+7duyVJly5dUlVVlUpKSrRkyRJduXIl8pympibN\nnDlTs2fP1tGjR9M7egDAmHzjfQ7+woULunDhgh566CENDw/r61//ug4ePKj9+/fry1/+stavX6+f\n/exnunz5spqbm9XV1aUVK1boxIkT6u/v1+LFi3X27FllZfGDAgBk2rgr7/Tp0/XQQw9JkqZMmaI5\nc+aov79fhw4dUn19vSSpvr5eBw8elCS1tbWprq5OOTk58vv9Ki4uVmdnZ5q/BQBALBNO697eXp08\neVKPPPKIBgYGlJ+fL0nKz8/XwMCAJOn8+fMqLCyMPKewsFD9/f0pHjIAYCImtMAPDw+rpqZGL730\nkqZOnTrqPp/PJ5/PN+Zzx7sPAJA+2fEe8J///Ec1NTVauXKlli1bJulGtV+4cEHTp0/XZ599pmnT\npkmSCgoK1NfXF3nuuXPnVFBQcMdrFhcX65NPPknV9wAAnjBjxgx9/PHHE378uAVvjFFjY6MCgYB+\n8IMfRI5XV1frlVdekSS98sorkYW/urpar776qq5du6aenh51d3ervLz8jtf95JNPZIzhZox+/OMf\nWz4Gu9yYC+aCubh1++Mfjfx+o1WrjC5fvnEs0TAet+Dfe+89/e53v1NZWZmCwaCkGx+DfOGFF1Rb\nW6uXX35Zfr9fr7/+uiQpEAiotrZWgUBA2dnZ2rNnD1s0AJCAoSFp/XrpzTelvXulb387+dcad4Ff\ntGiRRkZGYt73zjvvxDz+4osv6sUXX0x+RADgUe3tUmOjVFkpnT4t5ebe3evF3YNHeoVCIauHYBvM\nxS3MxS1emItUVnu0cS90ShefzycLTgsAthNd7bt2jV/tia6dFDwAWCBd1R6N3yEAABnW3i6VlUlX\nr97Ya0/H4i5R8ACQMZmo9mgUPABkQKaqPRoFDwBplOlqj0bBA0CaWFHt0Sh4AEgxK6s9GgUPAClk\ndbVHo+ABIAXsUu3RKHgAuEt2qvZoFDwAJMmO1R6NggeAJNi12qNR8ACQALtXezQKHgAmyAnVHo2C\nB4A4nFTt0Sh4ABiH06o9GgUPADE4tdqjUfAAcBsnV3s0Ch4A/s8N1R6NggcAuafao1HwADzNbdUe\njYIH4FlurPZoFDwAz3FztUej4AF4iturPRoFD8ATvFLt0Sh4AK7npWqPRsEDcC0vVns0Ch6AK3m1\n2qNR8ABcxevVHo2CB+AaVPtoFDwAx6PaY6PgATga1T42Ch6AI1Ht8VHwAByHap8YCh6AY1DtiaHg\nATgC1Z44Ch6ArVHtyaPgAdgW1X53KHgAtkO1pwYFD8BWqPbUoeAB2ALVnnoUPADLUe3pQcEDsAzV\nnl4UPABLUO3pR8EDyCiqPXPiFnxDQ4Py8/NVWloaOXbq1CktXLhQZWVlqq6u1tDQkCSpt7dXkydP\nVjAYVDAY1Jo1a9I3cgCOQ7Vnls8YY8Z7wPHjxzVlyhQ9+eSTOn36tCRpwYIF2rVrlyoqKrR//371\n9PRoy5Yt6u3t1dKlSyOPG/OkPp/inBaAi1DtqZHo2hm34CsqKpSXlzfqWHd3tyoqKiRJixcv1htv\nvJHgMAF4BdVunaTeZJ07d67a2tokSQcOHFBfX1/kvp6eHgWDQYVCIf3pT39KzSgBOM7QkLR6tVRf\nL7W0SK2tUm6u1aPylqTeZG1tbdWzzz6rrVu3qrq6WpMmTZIk3X///err61NeXp4+/PBDLVu2TGfO\nnNHUqVPveI1NmzZFvg6FQgqFQkl9AwDsp71damyUKitvVDsLe3LC4bDC4XDSz4+7By9p3L31s2fP\nauXKlfrzn/98x32VlZXauXOnHn744dEnZQ8ecCX22tMr5XvwsVy8eFGSNDIyom3btmn16tWSpMHB\nQV2/fl2S9Omnn6q7u1sPPvhgMqcA4DDstdtP3C2auro6dXR0aHBwUEVFRdq8ebOGh4fV0tIiSaqp\nqdFTTz0lSTp27Jg2btyonJwcZWVlae/evcrlZzPA1ah2+5rQFk3KT8oWDeAK0Xvtu3ax155uia6d\nXMkKIGFUuzPwu2gAJIS9dueg4AFMCNXuPBQ8gLiodmei4AGMiWp3NgoeQExUu/NR8ABGodrdg4IH\nEEG1uwsFD4BqdykKHvA4qt29KHjAo6h296PgAQ+i2r2Bggc8hGr3Fgoe8Aiq3XsoeMDlqHbvouAB\nF6PavY2CB1yIaodEwQOuQ7XjJgoecAmqHbej4AEXoNoRCwUPOBjVjvFQ8IBDUe2Ih4IHHIZqx0RR\n8ICDUO1IBAUPOADVjmRQ8IDNUe1IFgUP2BTVjrtFwQM2RLUjFSh4wEaodqQSBQ/YBNWOVKPgAYtR\n7UgXCh6wENWOdKLgAQtQ7cgECh7IMKodmULBAxlCtSPTKHggA6h2WIGCB9KIaoeVKHggTah2WI2C\nB1KMaoddUPBAClHtsBMKHkgBqh12RMEDd4lqh11R8ECSqHbYHQUPJIFqhxNQ8EACqHY4CQUPTBDV\nDqeh4IE4qHY4VdyCb2hoUH5+vkpLSyPHTp06pYULF6qsrEzV1dUaGhqK3NfU1KSZM2dq9uzZOnr0\naHpGDWQI1Q4ni7vAr1q1SkeOHBl17Omnn9b27dv10Ucfafny5dqxY4ckqaurS6+99pq6urp05MgR\nrVmzRiMjI+kZOZBGQ0PS6tVSfb3U0iK1tkq5uVaPCkhM3AW+oqJCeXl5o451d3eroqJCkrR48WK9\n8cYbkqS2tjbV1dUpJydHfr9fxcXF6uzsTMOwgfSh2uEWSb3JOnfuXLW1tUmSDhw4oL6+PknS+fPn\nVVhYGHlcYWGh+vv7UzBMIP2odrhNUm+ytra26tlnn9XWrVtVXV2tSZMmjflYn88X8/imTZsiX4dC\nIYVCoWSGAqREe7vU2ChVVt6odhZ22EE4HFY4HE76+Ukt8LNmzdJbb70lSTp79qx+//vfS5IKCgoi\nNS9J586dU0FBQczXiF7gAavwCRnY2e3xu3nz5oSen9QWzcWLFyVJIyMj2rZtm1avXi1Jqq6u1quv\nvqpr166pp6dH3d3dKi8vT+YUQNqx1w63i1vwdXV16ujo0ODgoIqKirR582YNDw+rpaVFklRTU6On\nnnpKkhQIBFRbW6tAIKDs7Gzt2bNnzC0awCpUO7zCZ4wxGT+pzycLTguM2mvftYu9djhLomsnV7LC\nE6h2eBG/iwaux147vIqCh2tR7fA6Ch6uRLUDFDxchmoHbqHg4RpUOzAaBQ/Ho9qB2Ch4OBrVDoyN\ngocjUe1AfBQ8HIdqByaGgodjUO1AYih4OALVDiSOgoetUe1A8ih42BbVDtwdCh62Q7UDqUHBw1ao\ndiB1KHjYAtUOpB4FD8tR7UB6UPCwDNUOpBcFD0tQ7UD6UfDIKKodyBwKHhlDtQOZRcEj7ah2wBoU\nPNKKagesQ8EjLah2wHoUPFKOagfsgYJHylDtgL1Q8EgJqh2wHwoed4VqB+yLgkfSqHbA3ih4JIxq\nB5yBgkdCqHbAOSh4TAjVDjgPBY+4qHbAmSh4jIlqB5yNgkdMVDvgfBQ8RqHaAfeg4BFBtQPuQsGD\nagdcioL3OKodcC8K3qOodsD9KHgPotoBb6DgPYRqB7yFgvcIqh3wHgre5ah2wLsoeBej2gFvo+Bd\niGoHIE2g4BsaGpSfn6/S0tLIsc7OTpWXlysYDGrBggU6ceKEJKm3t1eTJ09WMBhUMBjUmjVr0jdy\nxES1A7jJZ4wx4z3g+PHjmjJlip588kmdPn1akhQKhbRhwwY9/vjjOnz4sLZv3653331Xvb29Wrp0\naeRxY57U51Oc0yJBVDvgfomunXELvqKiQnl5eaOO3Xffffr8888lSVeuXFFBQUGCw0QqUe0AYklq\nD765uVmLFi3S2rVrNTIyovfffz9yX09Pj4LBoL70pS9p27ZtWrRoUcoGi9GodgDjSWqBb2xs1O7d\nu7V8+XIdOHBADQ0Nevvtt3X//ferr69PeXl5+vDDD7Vs2TKdOXNGU6dOveM1Nm3aFPk6FAopFAol\n+z14Unu71NgoVVbeqPbcXKtHBCDVwuGwwuFw0s+Puwcv6Y699XvvvVdffPGFJMkYo9zc3MiWTbTK\nykrt3LlTDz/88OiTsgefNKod8K6U78HHUlxcrI6ODklSe3u7SkpKJEmDg4O6fv26JOnTTz9Vd3e3\nHnzwwWROgRjYaweQiLhbNHV1dero6NDg4KCKioq0ZcsW7du3T88884yuXr2qyZMna9++fZKkY8eO\naePGjcrJyVFWVpb27t2rXPYO7hrVDiAZE9qiSflJ2aKZsOi99l272GsHvCzRtZMrWW2Kagdwt/hd\nNDbEXjuAVKDgbYRqB5BKFLxNUO0AUo2CtxjVDiBdKHgLUe0A0omCtwDVDiATKPgMo9oBZAoFnyFU\nO4BMo+AzgGoHYAUKPo2odgBWouDThGoHYDUKPsWodgB2QcGnENUOwE4o+BSg2gHYEQV/l6h2AHZF\nwSeJagdgdxR8Eqh2AE5AwSeAagfgJBT8BFHtAJyGgo+DagfgVBT8OKh2AE5GwcdAtQNwAwr+NlQ7\nALeg4P+PagfgNhS8qHYA7uTpgqfaAbiZZwueagfgdp4reKodgFd4quCpdgBe4omCp9oBeJHrC55q\nB+BVri14qh2A17my4Kl2AHBZwVPtAHCLawqeageA0Rxf8FQ7AMTm6IKn2gFgbI4seKodAOJzXMFT\n7QAwMY4peKodABLjiIKn2gEgcbYueKodAJJn24Kn2gHg7tiu4Kl2AEgNWxU81Q4AqRN3gW9oaFB+\nfr5KS0sjxzo7O1VeXq5gMKgFCxboxIkTkfuampo0c+ZMzZ49W0ePHp3QIIaGpNWrpfp6qaVFam2V\ncnOT+G4AABFxF/hVq1bpyJEjo46tX79eW7du1cmTJ7VlyxatX79ektTV1aXXXntNXV1dOnLkiNas\nWaORkZFxX9/r1R4Oh60egm0wF7cwF7cwF8mLu8BXVFQoLy9v1LH77rtPn3/+uSTpypUrKigokCS1\ntbWprq5OOTk58vv9Ki4uVmdnZ8zXpdpv4D/eW5iLW5iLW5iL5CX1Jmtzc7MWLVqktWvXamRkRO+/\n/74k6fz583r00UcjjyssLFR/f3/M1ygrkyorb1S7Fxd2AEi3pN5kbWxs1O7du/X3v/9dv/jFL9TQ\n0DDmY30+X8zjXq52AMgIMwE9PT1m3rx5kX+eOnVq5OuRkRFz7733GmOMaWpqMk1NTZH7Hn/8cfPB\nBx/c8XozZswwkrhx48aNWwK3GTNmTGTJjkhqi6a4uFgdHR36xje+ofb2dpWUlEiSqqurtWLFCj33\n3HPq7+9Xd3e3ysvL73j+xx9/nMxpAQAJiLvA19XVqaOjQ4ODgyoqKtKWLVu0b98+PfPMM7p69aom\nT56sffv2SZICgYBqa2sVCASUnZ2tPXv2jLlFAwBIL58xxlg9CABA6mXkStbr168rGAxq6dKlkqRL\nly6pqqpKJSUlWrJkia5cuZKJYdjC7XOxbt06zZkzR1/72tf0xBNPRD5+6gW3z8VNO3fuVFZWli5d\numTRyDIv1lz88pe/1Jw5czRv3jw9//zzFo4us26fi/EurHQzv9+vsrIyBYPByFZ3omtnRhb4l156\nSYFAILJd09zcrKqqKp09e1bf/OY31dzcnIlh2MLtc7FkyRKdOXNGp06dUklJiZqamiweYebcPheS\n1NfXp7ffflsPPPCAhSPLvNvn4t1339WhQ4f00Ucf6a9//avWrl1r8Qgz5/a5GOvCSrfz+XwKh8M6\nefJk5HqiRNfOtC/w586d0x/+8Ac9/fTTurkbdOjQIdXX10uS6uvrdfDgwXQPwxZizUVVVZWysm78\na3jkkUd07tw5K4eYMbHmQpKee+45bd++3cKRZV6sufjVr36lDRs2KCcnR5L0la98xcohZkysuRjr\nwkovuH0HPdG1M+0L/A9/+EPt2LEjsohJ0sDAgPLz8yVJ+fn5GhgYSPcwbCHWXERrbW3Vtz3yuxpi\nzUVbW5sKCwtVVlZm4cgyL9ZcdHd369ixY3r00UcVCoX0l7/8xcIRZk6suWhubtaPfvQjffWrX9W6\ndes881Ouz+fT4sWLNX/+fP3mN7+RlPjamdYF/s0339S0adMUDAbv+JPoJp/P54lP2sSbi5/85Cea\nNGmSVqxYYcHoMivWXPzrX//ST3/6U23evDnyOC+8/z/Wfxf//e9/dfnyZX3wwQfasWOHamtrLRxl\nZow1F4lcWOkm7733nk6ePKnDhw+rpaVFx48fH3X/hNbOhD41n6ANGzaYwsJC4/f7zfTp080999xj\nvve975lZs2aZzz77zBhjzPnz582sWbPSOQxbiDUXK1euNMYYs3//fvPYY4+Zf//73xaPMjNizUVN\nTY2ZNm2a8fv9xu/3m+zsbPPAAw+YgYEBq4ebVmP9P/Ktb33LhMPhyONmzJhhBgcHLRxp+o01F2Nd\nWOklmzZtMj//+c8TXjvTusBHC4fD5jvf+Y4xxph169aZ5uZmY8yNq1+ff/75TA3DFqLn4vDhwyYQ\nCJiLFy9aPCprRM9FNL/fb/7xj39YMCLrRM/Fr3/9a7Nx40ZjjDF/+9vfTFFRkZVDy7jouQgGg5E/\n7N555x0zf/58K4eWEf/85z/NF198YYwxZnh42Dz22GPmrbfeSnjtzOjf6HTzx4kXXnhBtbW1evnl\nl+X3+/X6669nchiWM8ZE5uL73/++rl27pqqqKknSwoULtWfPHiuHl3Gxfsz0wrZdLDe/74aGBjU0\nNKi0tFSTJk3Sb3/7W4tHlnk352KsCyvdbGBgQMuXL5d0Y7vuu9/9rpYsWaL58+cntHZyoRMAuJSt\n/so+AEDqsMADgEuxwAOAS7HAA4BLscADgEuxwAOAS7HAA4BLscADgEv9D8TPhbcY8WPyAAAAAElF\nTkSuQmCC\n",
+ "text": [
+ "<matplotlib.figure.Figure at 0x8136550>"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, Page Number : GUC-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "%pylab\n",
+ "#Tkinter package is used for graphics\n",
+ "from matplotlib.patches import Rectangle\n",
+ "from matplotlib.collections import PatchCollection\n",
+ "\n",
+ "e = Rectangle(xy=(35, -50), width=80, height=80)\n",
+ "fig = plt.gcf()\n",
+ "fig.gca().add_artist(e)\n",
+ "#e.set_clip_box(ax.bbox)\n",
+ "e.set_alpha(0.7)\n",
+ "pylab.xlim([20, 50])\n",
+ "pylab.ylim([-65, -35])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Using matplotlib backend: Qt4Agg\n",
+ "Populating the interactive namespace from numpy and matplotlib\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "WARNING: pylab import has clobbered these variables: ['e']\n",
+ "`%pylab --no-import-all` prevents importing * from pylab and numpy\n"
+ ]
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 22,
+ "text": [
+ "(-65, -35)"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, Page Number : GUC-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import turtle\n",
+ "turtle.speed(0)\n",
+ "\n",
+ "\n",
+ "turtle.forward(200)\n",
+ "turtle.left(120)\n",
+ "turtle.forward(200)\n",
+ "turtle.left(120)\n",
+ "turtle.forward(200)\n",
+ "turtle.left(180)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, Page Number: GUC-17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import turtle\n",
+ "turtle.speed(0)\n",
+ "\n",
+ "\n",
+ "turtle.forward(200)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(100)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(200)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, Page Number : GUC-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import turtle\n",
+ "turtle.speed(0)\n",
+ "\n",
+ "\n",
+ "turtle.forward(200)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(100)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(200)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7: Page Number: GUC-22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import*\n",
+ "speed(0)\n",
+ "i=0\n",
+ "while i < 360:\n",
+ " forward(1)\n",
+ " left(1)\n",
+ " i+=1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, Page Number:GUC-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import*\n",
+ "speed(0)\n",
+ "i=0\n",
+ "while i < 360:\n",
+ " forward(3)\n",
+ " left(3)\n",
+ " i+=3\n",
+ "\n",
+ "penup()\n",
+ "right(90)\n",
+ "forward(50)\n",
+ "left(90)\n",
+ "forward(100)\n",
+ "left(90)\n",
+ "pendown()\n",
+ "forward(200)\n",
+ "left(90)\n",
+ "forward(200)\n",
+ "left(90)\n",
+ "forward(200)\n",
+ "left(90)\n",
+ "forward(200)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9, Page Number : GUC-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import*\n",
+ "speed(0)\n",
+ "i=0\n",
+ "while i < 360:\n",
+ " forward(3)\n",
+ " left(1)\n",
+ " i+=1\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 54
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10, Page Number : GUC-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from turtle import*\n",
+ "speed(0)\n",
+ "\n",
+ "left(90)\n",
+ "forward(50)\n",
+ "i=0\n",
+ "while i < 180:\n",
+ " forward(1)\n",
+ " left(1)\n",
+ " i+=1\n",
+ " \n",
+ "forward(150)\n",
+ "left(90)\n",
+ "forward(250)\n",
+ "left(90)\n",
+ "forward(100)\n",
+ "left(90)\n",
+ "forward(140)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11, Page Number : GUC-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy as np\n",
+ "from matplotlib import pyplot as plt\n",
+ "\n",
+ "OX = [1,2,3,4]\n",
+ "OY = [200,590,670,435]\n",
+ "\n",
+ "fig = plt.figure()\n",
+ "\n",
+ "width = .35\n",
+ "ind = np.arange(len(OY))\n",
+ "plt.bar(ind, OY)\n",
+ "plt.xticks(ind + width / 2, OX)\n",
+ "\n",
+ "fig.autofmt_xdate()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12, Page Number : GUC-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from mpl_toolkits.mplot3d import Axes3D\n",
+ "import matplotlib.pyplot as plt\n",
+ "import numpy as np\n",
+ "\n",
+ "fig = plt.figure()\n",
+ "ax = fig.add_subplot(111, projection='3d')\n",
+ "for c, z in zip(['r'], [200,590,670,435]):\n",
+ " xs = np.arange(20)\n",
+ " ys = np.random.rand(20)\n",
+ " ax.bar(xs, ys, zs=z)\n",
+ " \n",
+ "ax.set_xlabel('X')\n",
+ "ax.set_ylabel('Y')\n",
+ "ax.set_zlabel('Z')\n",
+ "\n",
+ "plt.show()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13, Page Number : GUC-31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from pylab import *\n",
+ "\n",
+ "# make a square figure and axes\n",
+ "figure(1, figsize=(6,6))\n",
+ "ax = axes([0.1, 0.1, 0.8, 0.8])\n",
+ "\n",
+ "# The slices will be ordered and plotted counter-clockwise.\n",
+ "\n",
+ "sales = [200, 590, 670, 435]\n",
+ "explode=(0, 0.05, 0, 0)\n",
+ "\n",
+ "pie(sales, explode=explode,\n",
+ " autopct='%1.1f%%', shadow=True, startangle=90)\n",
+ " # The default startangle is 0, which would start\n",
+ " # the Frogs slice on the x-axis. With startangle=90,\n",
+ " # everything is rotated counter-clockwise by 90 degrees,\n",
+ " # so the plotting starts on the positive y-axis.\n",
+ "\n",
+ "\n",
+ "\n",
+ "show()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14, Page Number : GUC-34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "import turtle\n",
+ "\n",
+ "i=0\n",
+ "while i < 360:\n",
+ " turtle.forward(3)\n",
+ " turtle.left(3)\n",
+ " i+=3\n",
+ " \n",
+ "turtle.penup()\n",
+ "turtle.forward(200)\n",
+ "\n",
+ "turtle.pendown()\n",
+ "i=0\n",
+ "while i < 360:\n",
+ " turtle.forward(3)\n",
+ " turtle.left(3)\n",
+ " i+=3\n",
+ " \n",
+ "turtle.penup()\n",
+ "turtle.forward(100)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(50)\n",
+ "turtle.pendown()\n",
+ "turtle.forward(100)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(400)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(100)\n",
+ "turtle.right(90)\n",
+ "turtle.forward(100)\n",
+ "turtle.right(90)\n",
+ "turtle.forward(150)\n",
+ "turtle.right(90)\n",
+ "turtle.forward(100)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(50)\n",
+ "turtle.right(90)\n",
+ "turtle.forward(400)\n",
+ "turtle.right(90)\n",
+ "turtle.forward(50)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(50)\n",
+ "turtle.right(90)\n",
+ "turtle.forward(100)\n",
+ "turtle.left(90)\n",
+ "turtle.forward(100)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter4.ipynb b/A_First_course_in_Programming_with_C/Chapter4.ipynb
new file mode 100755
index 00000000..a3c3fdf3
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter4.ipynb
@@ -0,0 +1,431 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:beba487362ad72f7d0b5bcfa6d644d75a22e3d3f63f267f9db3f44d7a080a220"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 4: Input/Output Functions and Statements"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.0, Page number: IOF-5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable Declaration and Initialization\n",
+ "a = int(raw_input(\"\"))\n",
+ "b = int(raw_input(\"\"))\n",
+ "\n",
+ "#Calculation\n",
+ "sum1 = a + b\n",
+ "product = a * b\n",
+ "#Since sum is a keyword in python, sum1 is used\n",
+ "\n",
+ "#Output\n",
+ "print sum1, product"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1.1, Page number: IOF-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable initialization\n",
+ "a = int(raw_input(\"Enter Value to A : \"))\n",
+ "b = int(raw_input(\"Enter Value to B : \"))\n",
+ "\n",
+ "#Calculation\n",
+ "sum1 = a + b\n",
+ "product = a * b\n",
+ "#Since sum is a keyword in python, sum1 is used\n",
+ "\n",
+ "#Output\n",
+ "print \"SUM = \",sum1,\"\\nPRODUCT = \", product"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Value to A : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter Value to B : 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SUM = 8 \n",
+ "PRODUCT = 15\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page number: IOF-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "f = int(raw_input(\"Degree fahrenheit ? \"))\n",
+ "\n",
+ "#Calculation\n",
+ "c = 5.0/9.0 * (f-32)\n",
+ "\n",
+ "#Output\n",
+ "sys.stdout.write(\"Degree centigrade = %6.2f\"%(c))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Degree fahrenheit ? 105\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Degree centigrade = 40.56"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, Page number: IOF-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import sys\n",
+ "import math\n",
+ "\n",
+ "#Variable Initialization\n",
+ "a = int(raw_input(\"Enter three sides : \"))\n",
+ "b = int(raw_input(\"Enter three sides : \"))\n",
+ "c = int(raw_input(\"Enter three sides : \"))\n",
+ "\n",
+ "#Calculation\n",
+ "s = (a+b+c)/2\n",
+ "area = math.sqrt(s * (s-a) * (s-b) * (s-c))\n",
+ "\n",
+ "#Output\n",
+ "sys.stdout.write(\"Area of Triangle = %6.2f Sq.units\"%(area))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three sides : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three sides : 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter three sides : 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of Triangle = 6.48 Sq.units"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, Page number: IOF-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable Initialization\n",
+ "ch = raw_input(\"Enter a character : \")\n",
+ "\n",
+ "#Output\n",
+ "sys.stdout.write(\"\\n\\nASCII value of %c is %u\"%(ch,ord(ch)))\n",
+ "sys.stdout.write(\"\\nPress any key to stop...\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a character : A\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "ASCII value of A is 65\n",
+ "Press any key to stop..."
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, Page number: IOF-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable initialization\n",
+ "sno = raw_input(\"Enter service number : \")\n",
+ "pmr = int(raw_input(\"\\nPrevious month reading ? \"))\n",
+ "cmr = int(raw_input(\"\\nCurrent month reading ? \"))\n",
+ "\n",
+ "#Calculation\n",
+ "units = cmr - pmr\n",
+ "amt = units * 1.50\n",
+ "\n",
+ "#Output\n",
+ "sys.stdout.write(\"\\n Electricity Bill\")\n",
+ "sys.stdout.write(\"\\n ________________\")\n",
+ "sys.stdout.write(\"\\nService No. %s\"%(sno))\n",
+ "sys.stdout.write(\"\\nUnits Consumed : %d\"%(units))\n",
+ "sys.stdout.write(\"\\nElectricity Charges Rs. %0.2f\"%(amt))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter service number : TMR65358\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Previous month reading ? 4305\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Current month reading ? 4410\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " Electricity Bill\n",
+ " ________________\n",
+ "Service No. TMR65358\n",
+ "Units Consumed : 105\n",
+ "Electricity Charges Rs. 157.50"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, Page number: IOF-17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "a = int(raw_input(\"Enter value to A : \"))\n",
+ "b = int(raw_input(\"Enter value to B : \"))\n",
+ "\n",
+ "#Calculation\n",
+ "temp = a\n",
+ "a = b\n",
+ "b = temp\n",
+ "\n",
+ "#Output\n",
+ "sys.stdout.write(\"\\n\\nValue of A = %d\"%(a))\n",
+ "sys.stdout.write(\"\\nValue of B = %d\"%(b))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter value to A : 15\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter value to B : 250\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Value of A = 250\n",
+ "Value of B = 15"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter5.ipynb b/A_First_course_in_Programming_with_C/Chapter5.ipynb
new file mode 100755
index 00000000..0380f60d
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter5.ipynb
@@ -0,0 +1,657 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 5: Control Statements in C"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number : CSC-3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "a = int(raw_input(\"\\nEnter two numbers : \"))\n",
+ "b = int(raw_input(\"\"))\n",
+ "big = a\n",
+ "\n",
+ "#Processing\n",
+ "if b > big:\n",
+ " big = b\n",
+ "\n",
+ "#Output\n",
+ "print \"\\nBiggest number is \",big\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter two numbers : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Biggest number is 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number : CSC-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "a = int(raw_input(\"\\nEnter three numbers : \"))\n",
+ "b = int(raw_input(\"\"))\n",
+ "c = int(raw_input(\"\"))\n",
+ "big = a\n",
+ "\n",
+ "#Processing\n",
+ "if b > big:\n",
+ " big = b\n",
+ " \n",
+ "if c > big:\n",
+ " big = c\n",
+ " \n",
+ "#Output\n",
+ "print \"\\nBiggest number is \",big"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter three numbers : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "13\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Biggest number is 13\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, Page Number : CSC-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "a = int(raw_input(\"\\nEnter three numbers : \"))\n",
+ "b = int(raw_input(\"\"))\n",
+ "c = int(raw_input(\"\"))\n",
+ "\n",
+ "#Processing\n",
+ "if a > b:\n",
+ " if a > c:\n",
+ " big = a\n",
+ " else:\n",
+ " big = c\n",
+ "else:\n",
+ " if b > c:\n",
+ " big = b\n",
+ " else:\n",
+ " big = c\n",
+ " \n",
+ "#Output\n",
+ "print \"\\nBiggest number is \",big"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter three numbers : 18\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "13\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Biggest number is 18\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, Page Number : CSC-7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "x = float(raw_input(\"\\nEnter value to x and n : \"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "if n == 1:\n",
+ " y = 1 + x\n",
+ "else:\n",
+ " if n == 2:\n",
+ " y = 1 + x/n\n",
+ " else:\n",
+ " if n == 3:\n",
+ " y = 1 + pow(x,n)\n",
+ " else:\n",
+ " y = 1 + n*x\n",
+ " \n",
+ "print \"\\nValue of y(x,n) = \",y"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter value to x and n : 0.42\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Value of y(x,n) = 3.1\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, Page Number : CSC-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "x = float(raw_input(\"\\nEnter value to x and n : \"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "#There is no switch statement in python\n",
+ "if n == 1:\n",
+ " y = 1 + x\n",
+ "else:\n",
+ " if n == 2:\n",
+ " y = 1 + x/n\n",
+ " else:\n",
+ " if n == 3:\n",
+ " y = 1 + pow(x,n)\n",
+ " else:\n",
+ " y = 1 + n*x\n",
+ " \n",
+ "sys.stdout.write(\"\\nValue of y(x,n) = %6.2f\"%(y))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter value to x and n : 0.42\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Value of y(x,n) = 3.10"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, Page Number : CSC-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "sales = int(raw_input(\"\\nSales amount ? \"))\n",
+ "\n",
+ "if sales <= 500:\n",
+ " comm = 0.05 * sales\n",
+ "else:\n",
+ " if sales <= 2000:\n",
+ " comm = 35 + 0.10 * (sales - 500)\n",
+ " else:\n",
+ " if sales <= 5000:\n",
+ " comm = 185 + 0.12 * (sales - 2000)\n",
+ " else:\n",
+ " comm = 0.125 * sales\n",
+ " \n",
+ "sys.stdout.write(\"\\nCommission Amount Rs. %0.2f\"%(comm))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sales amount ? 4500\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Commission Amount Rs. 485.00"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, Page Number : CSC-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "import math\n",
+ "\n",
+ "a = int(raw_input(\"\\nEnter coefficients a,b and c : \"))\n",
+ "b = int(raw_input())\n",
+ "c = int(raw_input())\n",
+ "\n",
+ "d = b*b - 4*a*c\n",
+ "\n",
+ "if d > 0:\n",
+ " x1 = (-b + math.sqrt(d))/(2*a)\n",
+ " x2 = (-b - math.sqrt(d))/(2*a)\n",
+ " sys.stdout.write(\"\\nRoots are real and unequal\\n %6.2f %6.2f\"%(x1,x2))\n",
+ "else:\n",
+ " if d == 0:\n",
+ " x = -b / (2*a)\n",
+ " sys.stdout.write(\"\\nRoots are real and equal \\n %6.2f\"%(x))\n",
+ " else:\n",
+ " sys.stdout.write(\"\\nNo Real roots,roots are complex\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter coefficients a,b and c : 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Roots are real and unequal\n",
+ " -1.00 -2.00"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, Page Number : CSC-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "avg_marks = int(raw_input(\"\\nAverage Marks ? \"))\n",
+ "\n",
+ "if avg_marks >= 80 and avg_marks <= 100:\n",
+ " print \"\\nHonours\"\n",
+ "else:\n",
+ " if avg_marks >= 60 and avg_marks <= 79:\n",
+ " print \"\\nFirst Division\"\n",
+ " else:\n",
+ " if avg_marks >= 50 and avg_marks <= 59:\n",
+ " print \"\\nSecond Division\"\n",
+ " else:\n",
+ " if avg_marks <= 49 and avg_marks >= 0:\n",
+ " print \"\\nFail\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Average Marks ? 84\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Honours\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9, Page Number : CSC-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "units = int(raw_input(\"\\nEnter consumed units : \"))\n",
+ "\n",
+ "if units <= 200:\n",
+ " amt = 0.5 * units\n",
+ "else:\n",
+ " if units <= 400:\n",
+ " amt = 100 + 0.65 * (units - 200)\n",
+ " else:\n",
+ " if units <= 600:\n",
+ " amt = 230 + 0.8 * (units - 400)\n",
+ " else:\n",
+ " amt = 425 + 1.25 * (units - 600)\n",
+ " \n",
+ "sys.stdout.write(\"\\nAmount to be paid Rs.%0.2f\"%(amt))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter consumed units : 348\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Amount to be paid Rs.196.20"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10, Page Number : CSC-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "ts = int(raw_input(\"\\nEnter tensile strength : \"))\n",
+ "rh = int(raw_input(\"\\nEnter rockwell hardness : \"))\n",
+ "cc = int(raw_input(\"\\nEnter carbon content : \"))\n",
+ "\n",
+ "if ts >= 700:\n",
+ " if rh >= 200:\n",
+ " if cc <= 6:\n",
+ " print \"\\nGrade is A\"\n",
+ " else:\n",
+ " print \"\\nGrade is B\"\n",
+ " else:\n",
+ " if cc <= 6:\n",
+ " print \"\\nGrade is C\"\n",
+ " else:\n",
+ " print \"\\nGrade is E\"\n",
+ "else:\n",
+ " if rh >= 200:\n",
+ " if cc <= 6:\n",
+ " print \"\\nGrade is D\"\n",
+ " else:\n",
+ " print \"\\nGrade is E\"\n",
+ " else:\n",
+ " if cc <= 6:\n",
+ " print \"\\nGrade is E\"\n",
+ " else:\n",
+ " print \"\\nGrade is F\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter tensile strength : 800\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter rockwell hardness : 180\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter carbon content : 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Grade is C\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter6.ipynb b/A_First_course_in_Programming_with_C/Chapter6.ipynb
new file mode 100755
index 00000000..e2aad83c
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter6.ipynb
@@ -0,0 +1,1304 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 6: Loop Control Structures in C"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number : LCS-2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter value to n : \"))\n",
+ "\n",
+ "for i in range(1,n+1):\n",
+ " sys.stdout.write(\"%8d\"%(i))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter value to n : 15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number : LCS-3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "import numpy\n",
+ "import math\n",
+ "\n",
+ "print \"\\n--------------------------------\"\n",
+ "print \" X Y \"\n",
+ "print \"--------------------------------\"\n",
+ "\n",
+ "for x in numpy.arange(1.0,3.0+0.2,0.2):\n",
+ " y = 1.36*math.sqrt(1+x+x*x*x)+ pow(x,1.0/4) + math.exp(x)\n",
+ " sys.stdout.write(\"\\n %6.2f %6.2f\"%(x,y))\n",
+ " \n",
+ "print \"\\n--------------------------------\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "--------------------------------\n",
+ " X Y \n",
+ "--------------------------------\n",
+ "\n",
+ " 1.00 6.07\n",
+ " 1.20 7.06\n",
+ " 1.40 8.23\n",
+ " 1.60 9.60\n",
+ " 1.80 11.20\n",
+ " 2.00 13.09\n",
+ " 2.20 15.30\n",
+ " 2.40 17.91\n",
+ " 2.60 20.99\n",
+ " 2.80 24.64\n",
+ " 3.00 28.97\n",
+ "--------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, Page Number : LCS-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "k = int(raw_input(\"\\nEnter the number : \"))\n",
+ "\n",
+ "kfact = 1\n",
+ "\n",
+ "for i in range(1,k+1):\n",
+ " kfact = kfact * i\n",
+ " \n",
+ "print k,\" factorial is \",kfact"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the number : 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4 factorial is 24\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, Page Number : LCS-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = int(raw_input(\"\\nEnter value to N : \"))\n",
+ "\n",
+ "s = 0\n",
+ "\n",
+ "for i in range(1,n+1):\n",
+ " term = 0\n",
+ " for j in range(1,i+1):\n",
+ " term = term + j\n",
+ " s = s + term\n",
+ " \n",
+ "print \"\\nSum of the series S = \",s"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter value to N : 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of the series S = 20\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, Page Number : LCS-7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import numpy\n",
+ "import sys\n",
+ "\n",
+ "for x in numpy.arange(-1.5,1.5+0.5,0.5):\n",
+ " for y in numpy.arange(0,3.0+1.0,1.0):\n",
+ " z = 3*x*x + 2*y*y*y - 25.5\n",
+ " sys.stdout.write(\"\\n\\nValue of y(%0.2f,%0.2f) = %6.2f\"%(x,y,z))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Value of y(-1.50,0.00) = -18.75\n",
+ "\n",
+ "Value of y(-1.50,1.00) = -16.75\n",
+ "\n",
+ "Value of y(-1.50,2.00) = -2.75\n",
+ "\n",
+ "Value of y(-1.50,3.00) = 35.25\n",
+ "\n",
+ "Value of y(-1.00,0.00) = -22.50\n",
+ "\n",
+ "Value of y(-1.00,1.00) = -20.50\n",
+ "\n",
+ "Value of y(-1.00,2.00) = -6.50\n",
+ "\n",
+ "Value of y(-1.00,3.00) = 31.50\n",
+ "\n",
+ "Value of y(-0.50,0.00) = -24.75\n",
+ "\n",
+ "Value of y(-0.50,1.00) = -22.75\n",
+ "\n",
+ "Value of y(-0.50,2.00) = -8.75\n",
+ "\n",
+ "Value of y(-0.50,3.00) = 29.25\n",
+ "\n",
+ "Value of y(0.00,0.00) = -25.50\n",
+ "\n",
+ "Value of y(0.00,1.00) = -23.50\n",
+ "\n",
+ "Value of y(0.00,2.00) = -9.50\n",
+ "\n",
+ "Value of y(0.00,3.00) = 28.50\n",
+ "\n",
+ "Value of y(0.50,0.00) = -24.75\n",
+ "\n",
+ "Value of y(0.50,1.00) = -22.75\n",
+ "\n",
+ "Value of y(0.50,2.00) = -8.75\n",
+ "\n",
+ "Value of y(0.50,3.00) = 29.25\n",
+ "\n",
+ "Value of y(1.00,0.00) = -22.50\n",
+ "\n",
+ "Value of y(1.00,1.00) = -20.50\n",
+ "\n",
+ "Value of y(1.00,2.00) = -6.50\n",
+ "\n",
+ "Value of y(1.00,3.00) = 31.50\n",
+ "\n",
+ "Value of y(1.50,0.00) = -18.75\n",
+ "\n",
+ "Value of y(1.50,1.00) = -16.75\n",
+ "\n",
+ "Value of y(1.50,2.00) = -2.75\n",
+ "\n",
+ "Value of y(1.50,3.00) = 35.25"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, Page Number : LCS-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = int(raw_input(\"\\nEnter value to N : \"))\n",
+ "\n",
+ "s = 0\n",
+ "i = 1\n",
+ "\n",
+ "while i <= n:\n",
+ " s = s + i\n",
+ " i = i + 2\n",
+ " \n",
+ "print \"\\nSum of odd integers = \",s"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter value to N : 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of odd integers = 25\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, Page Number : LCS-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "print \"\\nInteger divisible by 7\"\n",
+ "\n",
+ "n = 7\n",
+ "\n",
+ "for i in range(1,50+1):\n",
+ " sys.stdout.write(\"%8d\"%(n))\n",
+ " n = n + 7"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Integer divisible by 7\n",
+ " 7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154 161 168 175 182 189 196 203 210 217 224 231 238 245 252 259 266 273 280 287 294 301 308 315 322 329 336 343 350"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, Page Number : LCS-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter the end value N : \"))\n",
+ "\n",
+ "print \"\\nIntegers not divisible by 7\"\n",
+ "\n",
+ "for k in range(1,n+1):\n",
+ " r = k % 7\n",
+ " if r != 0:\n",
+ " sys.stdout.write(\"%8d\"%(k))\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the end value N : 20\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Integers not divisible by 7\n",
+ " 1 2 3 4 5 6 8 9 10 11 12 13 15 16 17 18 19 20"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9, Page Number : LCS-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = int(raw_input(\"\\nEnter a positive integer : \"))\n",
+ "\n",
+ "q = n\n",
+ "s = 0\n",
+ "\n",
+ "while q > 0:\n",
+ " r = q % 10\n",
+ " s = s + r\n",
+ " q = q/ 10\n",
+ " \n",
+ "print \"\\nSum of digits = \",s"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter a positive integer : 2466\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of digits = 18\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10, Page Number : LCS-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = int(raw_input(\"\\nEnter an integer number : \"))\n",
+ "\n",
+ "q = n\n",
+ "s = 0\n",
+ "while q > 0:\n",
+ " r = q % 10\n",
+ " s = s + r*r*r\n",
+ " q = q/10\n",
+ " \n",
+ "if n == s:\n",
+ " print \"\\n\",n,\" is an Armstrong number\"\n",
+ "else:\n",
+ " print \"\\n\",n,\" is not an Armstrong number\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter an integer number : 153\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "153 is an Armstrong number\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11, Page Number : LCS-17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = int(raw_input(\"\\nEnter an integer number : \"))\n",
+ "\n",
+ "q = n\n",
+ "rn = 0\n",
+ "\n",
+ "while q > 0:\n",
+ " r = q % 10\n",
+ " rn = rn*10 + r\n",
+ " q = q/10\n",
+ " \n",
+ "print \"\\n\",n,\" is reversed as \",rn"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter an integer number : 18532\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "18532 is reversed as 23581\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12, Page Number : LCS-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "n = int(raw_input(\"\\nEnter an integer number : \"))\n",
+ "\n",
+ "q = n\n",
+ "rn = 0\n",
+ "\n",
+ "while q > 0:\n",
+ " r = q % 10\n",
+ " rn = rn*10 + r\n",
+ " q = q/10\n",
+ "\n",
+ "while rn > 0:\n",
+ " r = rn % 10\n",
+ " \n",
+ " #There is no switch statement in python\n",
+ " if r == 1:\n",
+ " print \"One\"\n",
+ " else:\n",
+ " if r == 2:\n",
+ " print \"Two\"\n",
+ " else:\n",
+ " if r == 3:\n",
+ " print \"Three\"\n",
+ " else:\n",
+ " if r == 4:\n",
+ " print \"Four\"\n",
+ " else:\n",
+ " if r == 5:\n",
+ " print \"Five\"\n",
+ " else:\n",
+ " if r == 6:\n",
+ " print \"Six\"\n",
+ " else:\n",
+ " if r == 7:\n",
+ " print \"Seven\"\n",
+ " else:\n",
+ " if r == 8:\n",
+ " print \"Eight\"\n",
+ " else:\n",
+ " if r == 9:\n",
+ " print \"Nine\"\n",
+ " else:\n",
+ " print \"Zero\"\n",
+ " rn = rn/10"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter an integer number : 4352\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Four\n",
+ "Three\n",
+ "Five\n",
+ "Two\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13, Page Number : LCS-20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "flag = 0\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter a positive integer : \"))\n",
+ "\n",
+ "for k in range(2,n/2+1):\n",
+ " if flag == 0:\n",
+ " r = n % k\n",
+ " if r == 0:\n",
+ " flag = 1\n",
+ " \n",
+ "if flag == 0:\n",
+ " print \"\\n\",n,\" is a prime number\"\n",
+ "else:\n",
+ " print \"\\n\",n,\" is not a prime number\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter a positive integer : 17\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "17 is a prime number\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14, Page Number : LCS-21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter the final term of the series : \"))\n",
+ "\n",
+ "n1 = 0\n",
+ "n2 = 1\n",
+ "\n",
+ "sys.stdout.write(\"%8d%8d\"%(n1,n2))\n",
+ "\n",
+ "newterm = n1 + n2\n",
+ "\n",
+ "while newterm <= n:\n",
+ " sys.stdout.write(\"%8d\"%(newterm))\n",
+ " n1 = n2\n",
+ " n2 = newterm\n",
+ " newterm = n1 + n2\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the final term of the series : 25\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 0 1 1 2 3 5 8 13 21"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15, Page Number : LCS-22"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = float(raw_input(\"\\nEnter x in radians : \"))\n",
+ "n = int(raw_input(\"\\nEnter end term power (n) : \"))\n",
+ "\n",
+ "s = 0\n",
+ "term = x\n",
+ "i = 1\n",
+ "\n",
+ "while i <= n:\n",
+ " s = s + term\n",
+ " term = (term*x*x*(-1))/((i+1)*(i+2))\n",
+ " i = i + 2\n",
+ " \n",
+ "print \"\\nSum of the series = \",s"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter x in radians : 0.52\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter end term power (n) : 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of the series = 0.496880137863\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16, Page Number : LCS-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = float(raw_input(\"\\nEnter x in radians : \"))\n",
+ "\n",
+ "s = 0\n",
+ "term = 1\n",
+ "i = 0\n",
+ "\n",
+ "while i <= n:\n",
+ " s = s + term\n",
+ " term = (term*x*x*(-1))/((i+1)*(i+2))\n",
+ " i = i + 2\n",
+ " \n",
+ "print \"\\nSum of the series = \",s"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter x in radians : 0.52\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of the series = 0.867819179677\n"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17, Page Number : LCS-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "import math\n",
+ "\n",
+ "s = 0\n",
+ "dr = 1\n",
+ "sign = 1\n",
+ "term = 1.0/dr * sign\n",
+ "\n",
+ "while (math.fabs(term) >= 1.0e-4):\n",
+ " s = s + term\n",
+ " dr = dr + 2\n",
+ " sign = sign * (-1)\n",
+ " term = (1.0/dr) * sign\n",
+ " \n",
+ "pie = s * 4\n",
+ "\n",
+ "sys.stdout.write(\"\\nValue of pie is %0.2f\"%(pie))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Value of pie is 3.14"
+ ]
+ }
+ ],
+ "prompt_number": 27
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 18, Page Number : LCS-27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter value to N : \"))\n",
+ "\n",
+ "s = 0\n",
+ "\n",
+ "for i in range(1,n+1):\n",
+ " s = s + 1.0/i\n",
+ " \n",
+ "sys.stdout.write(\"\\nSum of series = %8.4f\"%(s))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter value to N : 15\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of series = 3.3182"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 19, Page Number : LCS-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many lines ? \"))\n",
+ "\n",
+ "for l in range(1,n+1):\n",
+ " for i in range(1,n-l+1):\n",
+ " sys.stdout.write(\" \")\n",
+ " \n",
+ " m = l\n",
+ " for j in range(1,l+1):\n",
+ " sys.stdout.write(\"%6d\"%(m))\n",
+ " m = m + 1\n",
+ " m = m - 2\n",
+ " \n",
+ " for k in range(1,l):\n",
+ " sys.stdout.write(\"%6d\"%(m))\n",
+ " m = m - 1\n",
+ " \n",
+ " sys.stdout.write(\"\\n\")\n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many lines ? 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " 1\n",
+ " 2 3 2\n",
+ " 3 4 5 4 3\n",
+ " 4 5 6 7 6 5 4\n",
+ " 5 6 7 8 9 8 7 6 5\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 20, Page Number : LCS-29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many rows ? \"))\n",
+ "\n",
+ "print \"\\n\\t\\t\\t\\t PASCAL TRIANGLE\\n\"\n",
+ "\n",
+ "m = 1\n",
+ "\n",
+ "for l in range(0,n):\n",
+ " for i in range(40-3*l,0,-1):\n",
+ " sys.stdout.write(\" \")\n",
+ " \n",
+ " for j in range(0,l+1):\n",
+ " if j == 0 or l == 0:\n",
+ " m = 1\n",
+ " else:\n",
+ " m = (m*(l-j+1))/j\n",
+ " sys.stdout.write(\"%6d\"%(m))\n",
+ " sys.stdout.write(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many rows ? 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\t\t\t\t PASCAL TRIANGLE\n",
+ "\n",
+ " 1\n",
+ " 1 1\n",
+ " 1 2 1\n",
+ " 1 3 3 1\n",
+ " 1 4 6 4 1\n",
+ " 1 5 10 10 5 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 21, Page Number : LCS-31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "for i in range(1,5+1):\n",
+ " sys.stdout.write(\"\\n\\nMultiplication table for %d\\n\"%(i))\n",
+ " \n",
+ " for j in range(1,10+1):\n",
+ " sys.stdout.write(\"\\n%4d x %2d = %4d\"%(j,i,j*i))\n",
+ " \n",
+ " sys.stdout.write(\"\\n\\nPress any key to continue...\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Multiplication table for 1\n",
+ "\n",
+ " 1 x 1 = 1\n",
+ " 2 x 1 = 2\n",
+ " 3 x 1 = 3\n",
+ " 4 x 1 = 4\n",
+ " 5 x 1 = 5\n",
+ " 6 x 1 = 6\n",
+ " 7 x 1 = 7\n",
+ " 8 x 1 = 8\n",
+ " 9 x 1 = 9\n",
+ " 10 x 1 = 10\n",
+ "\n",
+ "Press any key to continue...\n",
+ "\n",
+ "Multiplication table for 2\n",
+ "\n",
+ " 1 x 2 = 2\n",
+ " 2 x 2 = 4\n",
+ " 3 x 2 = 6\n",
+ " 4 x 2 = 8\n",
+ " 5 x 2 = 10\n",
+ " 6 x 2 = 12\n",
+ " 7 x 2 = 14\n",
+ " 8 x 2 = 16\n",
+ " 9 x 2 = 18\n",
+ " 10 x 2 = 20\n",
+ "\n",
+ "Press any key to continue...\n",
+ "\n",
+ "Multiplication table for 3\n",
+ "\n",
+ " 1 x 3 = 3\n",
+ " 2 x 3 = 6\n",
+ " 3 x 3 = 9\n",
+ " 4 x 3 = 12\n",
+ " 5 x 3 = 15\n",
+ " 6 x 3 = 18\n",
+ " 7 x 3 = 21\n",
+ " 8 x 3 = 24\n",
+ " 9 x 3 = 27\n",
+ " 10 x 3 = 30\n",
+ "\n",
+ "Press any key to continue...\n",
+ "\n",
+ "Multiplication table for 4\n",
+ "\n",
+ " 1 x 4 = 4\n",
+ " 2 x 4 = 8\n",
+ " 3 x 4 = 12\n",
+ " 4 x 4 = 16\n",
+ " 5 x 4 = 20\n",
+ " 6 x 4 = 24\n",
+ " 7 x 4 = 28\n",
+ " 8 x 4 = 32\n",
+ " 9 x 4 = 36\n",
+ " 10 x 4 = 40\n",
+ "\n",
+ "Press any key to continue...\n",
+ "\n",
+ "Multiplication table for 5\n",
+ "\n",
+ " 1 x 5 = 5\n",
+ " 2 x 5 = 10\n",
+ " 3 x 5 = 15\n",
+ " 4 x 5 = 20\n",
+ " 5 x 5 = 25\n",
+ " 6 x 5 = 30\n",
+ " 7 x 5 = 35\n",
+ " 8 x 5 = 40\n",
+ " 9 x 5 = 45\n",
+ " 10 x 5 = 50\n",
+ "\n",
+ "Press any key to continue..."
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 22, Page Number : LCS-32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "n = int(raw_input(\"\\nEnter the binary number : \"))\n",
+ "\n",
+ "q = n\n",
+ "s = 0\n",
+ "k = 0\n",
+ "\n",
+ "while q > 0:\n",
+ " r = q % 10\n",
+ " s = s + r * pow(2,k)\n",
+ " q = q/10\n",
+ " k = k + 1\n",
+ " \n",
+ "print \"\\nThe decimal number is : \",s"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the binary number : 1101\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The decimal number is : 13\n"
+ ]
+ }
+ ],
+ "prompt_number": 40
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13, Page Number : LCS-34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "flag = 0\n",
+ "k = 0\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter the decimal number : \"))\n",
+ "\n",
+ "q = n\n",
+ "rbi = 0\n",
+ "\n",
+ "while q > 0:\n",
+ " r = q % 2\n",
+ " if r == 0 and flag == 0:\n",
+ " k = k + 1\n",
+ " else:\n",
+ " flag = 1\n",
+ " rbi = rbi *10 + r\n",
+ " q = q/2\n",
+ " \n",
+ "q = rbi\n",
+ "bi = 0\n",
+ "\n",
+ "while q > 0:\n",
+ " r = q % 10\n",
+ " bi = bi * 10 + r\n",
+ " q = q/10\n",
+ " if q == 0:\n",
+ " for i in range(1,k+1):\n",
+ " bi = bi * 10\n",
+ " \n",
+ "print \"\\nThe binary number is \",bi"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the decimal number : 28\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The binary number is 11100\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter7.ipynb b/A_First_course_in_Programming_with_C/Chapter7.ipynb
new file mode 100755
index 00000000..aa78904d
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter7.ipynb
@@ -0,0 +1,1655 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 7: Arrays and Subscripted Variables"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number : ASV-4"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "n = int(raw_input(\"\\nHow many integers ? \"))\n",
+ "x = [0 for i in range(0,n)]\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " x[i] = int(raw_input(\"\\nEnter the %dth value : \"%(i+1)))\n",
+ " \n",
+ "#Processing\n",
+ "#sum is a predefined function in python. so sum1 is used\n",
+ "sum1 = 0\n",
+ "for i in range(0,n):\n",
+ " sum1 = sum1 + x[i]\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nSum of all integers = %d\"%(sum1))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many integers ? 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the 1th value : 36\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the 2th value : 45\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the 3th value : 52\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the 4th value : 44\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the 5th value : 62\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of all integers = 239"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number : ASV-5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable initialization\n",
+ "n = int(raw_input(\"\\nHow many numbers ? \"))\n",
+ "sys.stdout.write(\"\\nEnter all those numbers \")\n",
+ "x = [0 for i in range(0,n)]\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " x[i] = int(raw_input(\"\"))\n",
+ " \n",
+ "#Processing\n",
+ "big = x[0]\n",
+ "for i in range(0,n):\n",
+ " if x[i] > big:\n",
+ " big = x[i]\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\n%d is the biggest number\"%(big))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many numbers ? 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all those numbers "
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-228\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "185\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "36\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "185 is the biggest number"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, Page Number : ASV-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "import math\n",
+ "\n",
+ "#Variable Initialization\n",
+ "n = int(raw_input(\"\\nHow many values ? \"))\n",
+ "x = [0.0 for i in range(0,n)]\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter all values in the list\\n\")\n",
+ "for i in range(0,n):\n",
+ " x[i] = float(raw_input(\"\"))\n",
+ " \n",
+ "#Processing\n",
+ "sum1 = 0\n",
+ "#Since sum is a predefined function in python, sum1 is used\n",
+ "for i in range(0,n):\n",
+ " sum1 = sum1 + x[i]\n",
+ "xbar = sum1 / n\n",
+ "vsum = 0\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " vsum = vsum + (x[i] - xbar) * (x[i] - xbar)\n",
+ "sigmax = vsum / n\n",
+ "sd = math.sqrt(sigmax)\n",
+ "\n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nArithmetic mean = %0.3f\"%(xbar))\n",
+ "sys.stdout.write(\"\\nVariance = %0.3f\"%(sigmax))\n",
+ "sys.stdout.write(\"\\nStandard deviation = %0.3f\"%(sd))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many values ? 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all values in the list\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Arithmetic mean = 3.617\n",
+ "Variance = 0.088\n",
+ "Standard deviation = 0.297"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, Page Number : ASV-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "n = int(raw_input(\"\\nHow many students ? \"))\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter all the marks \\n\")\n",
+ "for i in range(0,n):\n",
+ " x[i] = int(raw_input(\"\"))\n",
+ " \n",
+ "#Processing\n",
+ "sum1 = 0.0\n",
+ "#Since sum is a predefined function in python, sum1 is used\n",
+ "for i in range(0,n):\n",
+ " sum1 = sum1 + x[i]\n",
+ " \n",
+ "mean = float(sum1/n)\n",
+ "\n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nMean = %6.2f\"%(mean))\n",
+ "sys.stdout.write(\"\\n\\nMarks greater than mean : \")\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " if x[i] > mean:\n",
+ " sys.stdout.write(\"%5d\"%(x[i]))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many students ? 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all the marks \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "58\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "63\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "68\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "54\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "48\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Mean = 58.20\n",
+ "\n",
+ "Marks greater than mean : 63 68"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, Page Number : ASV-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "import math\n",
+ "\n",
+ "#Variable Initialization\n",
+ "n = int(raw_input(\"\\nHow many values ? \"))\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter all values in the list \\n\")\n",
+ "for i in range(0,n):\n",
+ " x[i] = float(raw_input(\"\"))\n",
+ " \n",
+ "psum = 0\n",
+ "nsum = 0\n",
+ "\n",
+ "#Processing\n",
+ "for i in range(0,n):\n",
+ " if x[i] > 0:\n",
+ " psum = psum + x[i]\n",
+ " else:\n",
+ " nsum = nsum + x[i]\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nSum of positive values = %0.2f\"%(psum))\n",
+ "sys.stdout.write(\"\\nSum of negative values = %0.2f\"%(nsum))\n",
+ "if psum > math.fabs(nsum):\n",
+ " sys.stdout.write(\"\\nPositive sum is greater in magnitude\")\n",
+ "else:\n",
+ " sys.stdout.write(\"\\nNegative sum is greater in magnitude\")\n",
+ " \n",
+ "diff = math.fabs(psum - math.fabs(nsum))\n",
+ "sys.stdout.write(\"\\nDifference in magnitude = %0.2f\"%(diff))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many values ? 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all values in the list \n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-16\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "12\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-9\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of positive values = 25.00\n",
+ "Sum of negative values = -37.00\n",
+ "Negative sum is greater in magnitude\n",
+ "Difference in magnitude = 12.00"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, Page Number : ASV-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "n = int(raw_input(\"How many numbers ? \"))\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter the list of %d numbers\\n\"%(n))\n",
+ "for i in range(0,n):\n",
+ " x[i] = int(raw_input(\"\"))\n",
+ " \n",
+ "#Processing\n",
+ "for i in range(0,n):\n",
+ " for j in range(i+1,n):\n",
+ " if x[i] > x[j]:\n",
+ " temp = x[i]\n",
+ " x[i] = x[j]\n",
+ " x[j] = temp\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nNumbers in ascending order\\n\")\n",
+ "for i in range(0,n):\n",
+ " sys.stdout.write(\"%5d\"%(x[i]))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many numbers ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the list of 4 numbers\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "32\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Numbers in ascending order\n",
+ " -10 5 20 32"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, Page Number : ASV-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "x = [0 for i in range(0,50)]\n",
+ "\n",
+ "#Variable Initialization\n",
+ "n = int(raw_input(\"\\nHow many values in the list ? \"))\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter all values in the list\\n\")\n",
+ "for i in range(0,n):\n",
+ " x[i] = int(raw_input(\"\"))\n",
+ "s = int(raw_input(\"\\nEnter the key value to be searched : \"))\n",
+ "\n",
+ "#Processing\n",
+ "for i in range(0,n):\n",
+ " if s == x[i]:\n",
+ " sys.stdout.write(\"\\n%d is available in %dth location\"%(s,i+1))\n",
+ " \n",
+ "if i == n+1:\n",
+ " sys.stdout.write(\"\\nThe key value %d is not present in the list\"%(s))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many values in the list ? 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all values in the list\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "13\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the key value to be searched : 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "3 is available in 4th location"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, Page Number : ASV-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "exchng = 0\n",
+ "n = int(raw_input(\"\\nHow many numbers ? \"))\n",
+ "sys.stdout.write(\"\\nEnter all numbers in the list\\n\")\n",
+ "for i in range(0,n):\n",
+ " x[i] = int(raw_input(\"\"))\n",
+ "\n",
+ "#Processing\n",
+ "for i in range(0,n-1):\n",
+ " for j in range(0,n-i-1):\n",
+ " if x[j] > x[j+1]:\n",
+ " temp = x[j]\n",
+ " x[j] = x[j+1]\n",
+ " x[j+1] = temp\n",
+ " exchng = exchng + 1\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nThe sorted list is\\n\")\n",
+ "for i in range(0,n):\n",
+ " sys.stdout.write(\"%5d\"%(x[i]))\n",
+ " \n",
+ "sys.stdout.write(\"\\nSorted in %d passes and %d exchanges\"%(n-1,exchng))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many numbers ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all numbers in the list\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The sorted list is\n",
+ " -2 3 6 8\n",
+ "Sorted in 3 passes and 3 exchanges"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9, Page Number : ASV-17"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable declaration and initialization\n",
+ "\n",
+ "m = int(raw_input(\"\\nHow many rows and columns ? \"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "a = [[0 for i in range(0,m)] for j in range(0,n)]\n",
+ "b = [[0 for i in range(0,m)] for j in range(0,n)]\n",
+ "c = [[0 for i in range(0,m)] for j in range(0,n)]\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter A matrix\\n\")\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ " \n",
+ "sys.stdout.write(\"\\nEnter B matrix\\n\")\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " b[i][j] = int(raw_input(\"\"))\n",
+ " \n",
+ "#Processing\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " c[i][j] = a[i][j] + b[i][j]\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nResultant matrix is \\n\")\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " sys.stdout.write(\"%6d\"%(c[i][j]))\n",
+ " sys.stdout.write(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many rows and columns ? 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter A matrix\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter B matrix\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Resultant matrix is \n",
+ " 8 0\n",
+ " 4 -1\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10, Page Number : ASV-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable declaration and initialization\n",
+ "\n",
+ "m = int(raw_input(\"\\nEnter order of A matrix : \"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "a = [[0 for i in range(0,m)] for j in range(0,n)]\n",
+ "b = [[0 for i in range(0,m)] for j in range(0,n)]\n",
+ "c = [[0 for i in range(0,m)] for j in range(0,n)]\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter A matrix\\n\")\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter order of B matrix : \"))\n",
+ "l = int(raw_input(\"\"))\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter B matrix\\n\")\n",
+ "for i in range(0,n):\n",
+ " for j in range(0,l):\n",
+ " b[i][j] = int(raw_input(\"\"))\n",
+ " \n",
+ "#Processing\n",
+ "for i in range(0,n):\n",
+ " for j in range(0,l):\n",
+ " c[i][j] = 0\n",
+ " for k in range(0,n):\n",
+ " c[i][j] = c[i][j] + a[i][k] * b[k][j]\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nResultant matrix is \\n\")\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,l):\n",
+ " sys.stdout.write(\"%6d\"%(c[i][j]))\n",
+ " sys.stdout.write(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter order of A matrix : 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter A matrix\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter order of B matrix : 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter B matrix\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Resultant matrix is \n",
+ " 4 14\n",
+ " 16 -20\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11, Page Number : ASV-20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable declaration and initialization\n",
+ "\n",
+ "m = int(raw_input(\"\\nEnter order of the matrix : \"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "a = [[0 for i in range(0,10)] for j in range(0,10)]\n",
+ "at = [[0 for i in range(0,10)] for j in range(0,10)]\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter the matrix values\\n\")\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "#Processing\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " at[j][i] = a[i][j]\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nThe transposed matrix is\\n\")\n",
+ "for i in range(0,n):\n",
+ " for j in range(0,m):\n",
+ " sys.stdout.write(\"%6d\"%(at[i][j]))\n",
+ " sys.stdout.write(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter order of the matrix : 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the matrix values\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The transposed matrix is\n",
+ " -3 3\n",
+ " 6 2\n",
+ " 0 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12, Page Number : ASV-21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable declaration and initialization\n",
+ "\n",
+ "m = int(raw_input(\"\\nEnter order of the square matrix : \"))\n",
+ "\n",
+ "a = [[0 for i in range(0,10)] for j in range(0,10)]\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter the matrix\\n\")\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,m):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "#Processing\n",
+ "flag = 0\n",
+ "for i in range(0,m):\n",
+ " if flag == 0:\n",
+ " for j in range(0,m):\n",
+ " if flag == 0:\n",
+ " if a[i][j] == a[j][i]:\n",
+ " continue\n",
+ " else:\n",
+ " flag = 1\n",
+ "\n",
+ "#Output\n",
+ "if flag == 0:\n",
+ " sys.stdout.write(\"\\nThe given matrix is a symmetric matrix\")\n",
+ "else:\n",
+ " sys.stdout.write(\"\\nThe given matrix is not a symmetric matrix\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter order of the square matrix : 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the matrix\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-7\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The given matrix is a symmetric matrix"
+ ]
+ }
+ ],
+ "prompt_number": 38
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13, Page Number : ASV-23"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "#Variable declaration and initialization\n",
+ "\n",
+ "m = int(raw_input(\"\\nEnter order of the square matrix : \"))\n",
+ "\n",
+ "a = [[0 for i in range(0,10)] for j in range(0,10)]\n",
+ "\n",
+ "sys.stdout.write(\"\\nEnter the matrix\\n\")\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,m):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "#Processing \n",
+ "sum1 = 0\n",
+ "#since sum is a predefined function in python, sum1 is used\n",
+ "for i in range(0,m):\n",
+ " sum1 = sum1 + a[i][i]\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nTrace of the matrix = %d\"%(sum1))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter order of the square matrix : 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the matrix\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Trace of the matrix = 6"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter8.ipynb b/A_First_course_in_Programming_with_C/Chapter8.ipynb
new file mode 100755
index 00000000..2121f615
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter8.ipynb
@@ -0,0 +1,665 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 8: String Manipulations in C<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 1, Page number: SMC-4<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Count a character in a string\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "st = raw_input(\"Enter the string : \")\n",
+ "ch = raw_input(\"Which char to be counted ?\")\n",
+ "\n",
+ "#Checking\n",
+ "l = len(st)\n",
+ "count = 0\n",
+ "for i in st:\n",
+ " if i == ch:\n",
+ " count = count + 1\n",
+ " \n",
+ "#Output\n",
+ "sys.stdout.write(\"\\nThe character %c occurs %d times\"%(ch,count))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the string : MISSISSIPPI\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Which char to be counted ?S\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The character S occurs 4 times"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2, Page number: SMC-5<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Counting vowels\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "st = raw_input(\"Enter the sentence :\")\n",
+ "count = 0\n",
+ "\n",
+ "#Processing\n",
+ "for i in st:\n",
+ " if i == 'A'or i == 'E' or i == 'I' or i == 'O' or i == 'U' or i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':\n",
+ " count = count + 1\n",
+ "\n",
+ "#Result\n",
+ "sys.stdout.write(\"%d vowels are present in the sentence\"%(count))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the sentence :This is a book\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5 vowels are present in the sentence"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 3, Page number: SMC-6<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Palindrome or not \n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "rst = ['' for i in range(0,20)]\n",
+ "st = raw_input(\"Enter the string : \")\n",
+ "j = len(st)-1\n",
+ "\n",
+ "#Processing\n",
+ "rst = st[::-1]\n",
+ "\n",
+ "#Result\n",
+ "if st == rst:\n",
+ " sys.stdout.write(\"%s is a palindrome string\"%(st))\n",
+ "else:\n",
+ " sys.stdout.write(\"%s is not a palindrome string\"%(st))\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the string : HYDERABAD\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "HYDERABAD is not a palindrome string"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 4, Page number: SMC-8<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#String Concatenation\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "st1 = raw_input(\"Enter first string : \")\n",
+ "st2 = raw_input(\"Enter second string : \")\n",
+ "\n",
+ "#Processing\n",
+ "st = st1 + \" \" + st2\n",
+ "\n",
+ "#Result\n",
+ "sys.stdout.write(\"\\nResultant string is %s\"%(st))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter first string : NEW\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter second string : DELHI\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Resultant string is NEW DELHI"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 5, Page number: SMC-10<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Print greater string\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "st1 = raw_input(\"Enter string 1 : \")\n",
+ "st2 = raw_input(\"Enter string 2 : \")\n",
+ "\n",
+ "\n",
+ "#Result\n",
+ "if st1 > st2:\n",
+ " sys.stdout.write(\"%s is alphabetically greater string\"%(st1))\n",
+ "else:\n",
+ " sys.stdout.write(\"%s is alphabetically greater string\"%(st2))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string 1 : ALPHA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter string 2 : BETA\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "BETA is alphabetically greater string"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 6, Page number: SMC-11<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#String sorting\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "names = [\"\" for i in range(0,50)]\n",
+ "n = int(raw_input(\"How many names ? \"))\n",
+ "sys.stdout.write(\"\\nEnter the %d names one by one\"%(n))\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " names[i] = raw_input(\"\")\n",
+ " \n",
+ "for i in range(0,n):\n",
+ " for j in range(i+1,n):\n",
+ " if names[i] > names[j]:\n",
+ " temp = names[i]\n",
+ " names[i] = names[j]\n",
+ " names[j] = temp\n",
+ " \n",
+ "#Result\n",
+ "sys.stdout.write(\"\\nNames in alphabetical order\")\n",
+ "for i in range(0,n):\n",
+ " sys.stdout.write(\"\\n%s\"%(names[i]))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many names ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the 4 names one by one"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "DEEPAK\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SHERIN\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "SONIKA\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "ARUN\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Names in alphabetical order\n",
+ "ARUN\n",
+ "DEEPAK\n",
+ "SHERIN\n",
+ "SONIKA"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 7, Page number: SMC-13<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Lower case text to upper case\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "st = raw_input(\"Enter a sentence : \")\n",
+ "\n",
+ "#Result\n",
+ "st = st.upper()\n",
+ "\n",
+ "sys.stdout.write(\"\\nThe converted upper case string is \\n%s\"%(st))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a sentence : logical thinking is a must to learn programming\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The converted upper case string is \n",
+ "LOGICAL THINKING IS A MUST TO LEARN PROGRAMMING"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 8, Page number: SMC-14<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Determine the longest word\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "\n",
+ "#Variable Initialization\n",
+ "st = raw_input(\"Enter a sentence \")\n",
+ "\n",
+ "#Processing\n",
+ "lngst = max(st.split(), key=len)\n",
+ "\n",
+ "#Result\n",
+ "sys.stdout.write(\"\\nLongest word is %s\"%(lngst))\n",
+ "sys.stdout.write(\"\\nPress any key to continue...\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a sentence SMALL THINGS MAKE PERFECTION BUT PERFECTION IS NO SMALL THING\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Longest word is PERFECTION\n",
+ "Press any key to continue..."
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 9, Page number: SMC-16<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Remove particular word in a text\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "st = raw_input(\"Enter a sentence : \")\n",
+ "\n",
+ "omit = raw_input(\"\\nEnter word to omit : \")\n",
+ "word = st.split()\n",
+ "newst = ' '.join([i for i in word if i not in omit])\n",
+ "\n",
+ "#Result\n",
+ "sys.stdout.write(\"\\nAfter omitting the word %s\\n%s\"%(omit,newst))\n",
+ "sys.stdout.write(\"\\nPress any key to continue...\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter a sentence : TO ACCESS THE NAME OF THE CITY IN THE LIST\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter word to omit : THE\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "After omitting the word THE\n",
+ "TO ACCESS NAME OF CITY IN LIST\n",
+ "Press any key to continue..."
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 10, Page number: SMC-17<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Telegram expense calculation\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "st = raw_input(\"Type the sentence for Telegram : \")\n",
+ "\n",
+ "count = len(st.split())\n",
+ "\n",
+ "if count <= 10:\n",
+ " amt = 5\n",
+ "else:\n",
+ " amt = 5 + (count - 10) * 1.25\n",
+ " \n",
+ "#Result\n",
+ "sys.stdout.write(\"\\nAmount to be paid for telegram = Rs. %6.2f\"%(amt))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Type the sentence for Telegram : Congratulations on your success in Examinations.\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Amount to be paid for telegram = Rs. 5.00"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 11, Page number: SMC-19<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#Count lines, words and characters\n",
+ "\n",
+ "import sys\n",
+ "\n",
+ "#Variable Initialization\n",
+ "txt = raw_input(\"Enter the text, type $st end\\n\\n\")\n",
+ "\n",
+ "wds = 0\n",
+ "lns = 0\n",
+ "chs = 0\n",
+ "\n",
+ "#Processing\n",
+ "for i in txt:\n",
+ " if i == ',' or i == '!' or i == '\\t' or i == ' ':\n",
+ " wds += 1\n",
+ " chs += 1\n",
+ " else:\n",
+ " if i == '?' :\n",
+ " \n",
+ " lns += 1\n",
+ " else:\n",
+ " if i == '.':\n",
+ " wds += 1\n",
+ " lns += 1\n",
+ " else:\n",
+ " chs += 1\n",
+ " \n",
+ "#Result\n",
+ "sys.stdout.write(\"\\n\\nNumber of char(incl.blanks) = %d\"%(chs))\n",
+ "sys.stdout.write(\"\\nNumber of words = %d\"%(wds))\n",
+ "sys.stdout.write(\"\\nNumber of lines = %d\"%(lns))\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the text, type $st end\n",
+ "\n",
+ "What is a string? How do you initialize it? Explain with example.$\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "Number of char(incl.blanks) = 63\n",
+ "Number of words = 12\n",
+ "Number of lines = 3"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/Chapter9.ipynb b/A_First_course_in_Programming_with_C/Chapter9.ipynb
new file mode 100755
index 00000000..34f208c0
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter9.ipynb
@@ -0,0 +1,1638 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 9: Functions in C"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number: FNC-5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def fact(k):\n",
+ " p = 1\n",
+ " for i in range(1,k+1):\n",
+ " p = p * i\n",
+ " return p\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter value to n and r : \"))\n",
+ "r = int(raw_input(\"\"))\n",
+ "\n",
+ "ncr = fact(n)/ (fact(r)*fact(n-r))\n",
+ "\n",
+ "print \"\\nValue of nCr = \",ncr"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter value to n and r : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Value of nCr = 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number: FNC-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def big(a,b,c):\n",
+ " if a > b:\n",
+ " if a > c:\n",
+ " return a\n",
+ " else:\n",
+ " return c\n",
+ " else:\n",
+ " if b > c:\n",
+ " return b\n",
+ " else:\n",
+ " return c\n",
+ " \n",
+ "t1 = int(raw_input(\"\\nEnter three test scores : \"))\n",
+ "t2 = int(raw_input(\"\"))\n",
+ "t3 = int(raw_input(\"\"))\n",
+ "\n",
+ "a1 = int(raw_input(\"\\nEnter three assignment scores : \"))\n",
+ "a2 = int(raw_input(\"\"))\n",
+ "a3 = int(raw_input(\"\"))\n",
+ "\n",
+ "total = big(t1,t2,t3) + big(a1,a2,a3)\n",
+ "\n",
+ "print \"\\nTotal marks = \",total"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter three test scores : 62\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "70\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "58\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter three assignment scores : 17\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "21\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "23\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Total marks = 93\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 3, Page Number: FNC-8"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "def cosine(x):\n",
+ " x = x * 3.14/180\n",
+ " \n",
+ " s = 0\n",
+ " term = 1\n",
+ " i = 0\n",
+ " \n",
+ " for k in range(1,15+1):\n",
+ " s = s + term\n",
+ " term = term*x*x*(-1)/((i+1)*(i+2))\n",
+ " i = i + 2\n",
+ " return s\n",
+ "\n",
+ "x = 0\n",
+ "print \"\\n------------------------------------\"\n",
+ "print \" x in degrees cos(x) \"\n",
+ "print \"------------------------------------\"\n",
+ "\n",
+ "while x <= 180:\n",
+ " sys.stdout.write(\"\\n\\t%6.0f %6.2f\"%(x,cosine(x)))\n",
+ " x = x + 30\n",
+ " \n",
+ "print \"\\n------------------------------------\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "------------------------------------\n",
+ " x in degrees cos(x) \n",
+ "------------------------------------\n",
+ "\n",
+ "\t 0 1.00\n",
+ "\t 30 0.87\n",
+ "\t 60 0.50\n",
+ "\t 90 0.00\n",
+ "\t 120 -0.50\n",
+ "\t 150 -0.87\n",
+ "\t 180 -1.00\n",
+ "------------------------------------\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 4, Page Number: FNC-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def gcd(x,y):\n",
+ " if x >= y:\n",
+ " nr = x\n",
+ " dr = y\n",
+ " else:\n",
+ " nr = y\n",
+ " dr = x\n",
+ " r = nr % dr\n",
+ " while r != 0:\n",
+ " nr = dr\n",
+ " dr = r\n",
+ " r = nr % dr\n",
+ " \n",
+ " return dr\n",
+ "\n",
+ "a = int(raw_input(\"\\nEnter three integers : \"))\n",
+ "b = int(raw_input(\"\"))\n",
+ "c = int(raw_input(\"\"))\n",
+ "\n",
+ "d1 = gcd(a,b)\n",
+ "d2 = gcd(a,c)\n",
+ "d3 = gcd(b,c)\n",
+ "\n",
+ "if d1 == d2:\n",
+ " if d1 == d3:\n",
+ " print \"\\nGreatest common divisor is \",d1\n",
+ " else:\n",
+ " print \"\\nGreatest common divisor is \",gcd(d1,d3)\n",
+ "else:\n",
+ " print \"\\nGreatest common divisor is \",gcd(d1,d2)\n",
+ " \n",
+ "print \"\\n\\nPress any key to continue...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter three integers : 45\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "27\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "81\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Greatest common divisor is 9\n",
+ "\n",
+ "\n",
+ "Press any key to continue...\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 5, Page Number: FNC-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def reverse(n):\n",
+ " rn = 0\n",
+ " while n > 0:\n",
+ " r = n % 10\n",
+ " rn = rn * 10 + r\n",
+ " n = n / 10\n",
+ " return rn\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter the integer : \"))\n",
+ "\n",
+ "print \"\\n\",n,\" is erversed as \",reverse(n)\n",
+ "print \"\\nPress any key to continue...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the integer : 2846\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "2846 is erversed as 6482\n",
+ "\n",
+ "Press any key to continue...\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6, Page Number: FNC-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def compare(s1,s2):\n",
+ " if s1 == s2:\n",
+ " return 0\n",
+ " if s1 > s2:\n",
+ " return 1\n",
+ " if s1 < s2:\n",
+ " return -1\n",
+ " \n",
+ "s1 = raw_input(\"\\nEnter the first string : \")\n",
+ "s2 = raw_input(\"\\nEnter the second string : \")\n",
+ "\n",
+ "print \"\\nThe result is \",compare(s1,s2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the first string : MUMBAI\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the second string : MYSORE\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The result is -1\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 7, Page Number: FNC-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "def amean(x,n):\n",
+ " s = 0\n",
+ " for i in range(0,n):\n",
+ " s = s + x[i]\n",
+ " return s/n\n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many values? \"))\n",
+ "print \"\\nEnter all values\\n\"\n",
+ "\n",
+ "x = [0.0 for i in range(0,10)]\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " x[i] = float(raw_input(\"\"))\n",
+ " \n",
+ "sys.stdout.write(\"\\nArithmetic mean = %6.2f\"%(amean(x,n)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many values? 6\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4.0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3.8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Arithmetic mean = 3.62"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8, Page Number: FNC-14"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def elem_sum(a,m,n):\n",
+ " s = 0\n",
+ " for i in xrange(m):\n",
+ " for j in xrange(n):\n",
+ " s = s + a[i][j]\n",
+ " \n",
+ " return s\n",
+ "\n",
+ "m = int(raw_input(\"\\nHow many rows and columns : \"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "a = [[0 for i in range(0,10)] for i in range(0,10)]\n",
+ "\n",
+ "print \"\\nEnter the matrix values\\n\"\n",
+ "\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "\n",
+ "print \"\\nSum of all elements in the matrix = \",elem_sum(a,m,n)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many rows and columns : 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the matrix values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Sum of all elements in the matrix = 12\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 9, Page Number: FNC-15"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def reverse(st):\n",
+ " \n",
+ " i = len(st) - 1\n",
+ " rst = \"\"\n",
+ " while i >= 0:\n",
+ " rst = rst + st[i]\n",
+ " i = i -1\n",
+ " \n",
+ " return rst\n",
+ "\n",
+ "st = raw_input(\"\\nEnter a string : \")\n",
+ "\n",
+ "print \"\\n\",st,\" is reversed as \",reverse(st)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter a string : NEW DELHI\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " \n",
+ "NEW DELHI is reversed as IHLED WEN\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 10, Page Number: FNC-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def bi_search(x,n,s):\n",
+ " flag = 0\n",
+ " start = 0\n",
+ " end = n\n",
+ " \n",
+ " while start < end and flag == 0:\n",
+ " mid = (start+end)/2\n",
+ " if x[mid] > s:\n",
+ " end = mid\n",
+ " else:\n",
+ " if x[mid] < s:\n",
+ " start = mid + 1\n",
+ " else:\n",
+ " flag = 1\n",
+ " return flag\n",
+ "\n",
+ "n = int(raw_input(\"\\nHow many numbers ? \"))\n",
+ "\n",
+ "print \"\\nEnter all numbers in the list\\n\"\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " x[i] = int(raw_input(\"\"))\n",
+ " \n",
+ "s = int(raw_input(\"\\nEnter the number to be searched : \"))\n",
+ "\n",
+ "if bi_search(x,n,s):\n",
+ " print \"\\nThe number \",s,\" is present in the list\"\n",
+ "else:\n",
+ " print \"\\nThe number \",s,\" is not present in the list\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many numbers ? 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter all numbers in the list\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "13\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "19\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "21\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "25\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "26\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "29\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "35\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "42\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the number to be searched : 19\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The number 19 is present in the list\n"
+ ]
+ }
+ ],
+ "prompt_number": 21
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 11, Page Number: FNC-19"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def fact(k):\n",
+ " if k == 1:\n",
+ " return 1\n",
+ " else:\n",
+ " return k*fact(k-1)\n",
+ " \n",
+ "n = int(raw_input(\"\\nEnter values to n and r : \"))\n",
+ "r = int(raw_input(\"\"))\n",
+ "\n",
+ "ncr = fact(n)/(fact(r)*fact(n-r))\n",
+ "\n",
+ "print \"\\nValue of nCr = \",ncr\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter values to n and r : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Value of nCr = 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 12, Page Number: FNC-20"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "def power(x,n):\n",
+ " if n == 1:\n",
+ " return x\n",
+ " else:\n",
+ " return x*power(x,n-1)\n",
+ " \n",
+ "x = float(raw_input(\"\\nEnter value to x : \"))\n",
+ "n = int(raw_input(\"\\nEnter its power : \"))\n",
+ "\n",
+ "sys.stdout.write(\"\\n%6.2f raise to %d is %6.2f\"%(x,n,power(x,n)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter value to x : 4.2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter its power : 3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " 4.20 raise to 3 is 74.09"
+ ]
+ }
+ ],
+ "prompt_number": 24
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 13, Page Number: FNC-21"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "\n",
+ "def fibo(t1,t2,count):\n",
+ " if count >= n:\n",
+ " return\n",
+ " else:\n",
+ " t3 = t1 + t2\n",
+ " sys.stdout.write(\"%5d\"%(t3))\n",
+ " count = count + 1\n",
+ " t1 = t2\n",
+ " t2 = t3\n",
+ " fibo(t1,t2,count)\n",
+ " \n",
+ "n = int(raw_input(\"\\nHow many terms to be printed ? \"))\n",
+ "t1 = 0\n",
+ "t2 = 1\n",
+ "\n",
+ "print \"\\nThe first \",n,\" terms in Fibonacci series are\\n\"\n",
+ "sys.stdout.write(\"%5d %5d\"%(t1,t2))\n",
+ "\n",
+ "count = 2\n",
+ "fibo(t1,t2,count)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many terms to be printed ? 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The first 10 terms in Fibonacci series are\n",
+ "\n",
+ " 0 1 1 2 3 5 8 13 21 34"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 14, Page Number: FNC-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "def matadd():\n",
+ " for i in xrange(m):\n",
+ " for j in xrange(n):\n",
+ " c[i][j] = a[i][j] + b[i][j]\n",
+ " \n",
+ "m = int(raw_input(\"\\nHow many rows and columns ?\"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "a = [[0 for i in range(0,10)]for i in range(0,10)]\n",
+ "b = [[0 for i in range(0,10)]for i in range(0,10)]\n",
+ "c = [[0 for i in range(0,10)]for i in range(0,10)]\n",
+ "\n",
+ "#Read matrices\n",
+ "print \"\\nEnter A matrix values\\n\"\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ " \n",
+ "print \"\\nEnter B matrix values\\n\"\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " b[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "matadd()\n",
+ "\n",
+ "print \"\\nResultant matrix is \\n\"\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " sys.stdout.write(\"%5d\"%(c[i][j]))\n",
+ " sys.stdout.write(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many rows and columns ?2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter A matrix values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter B matrix values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Resultant matrix is \n",
+ "\n",
+ " 8 0\n",
+ " 4 -1\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 15, Page Number: FNC-29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "def matmul():\n",
+ " for i in xrange(m):\n",
+ " for j in xrange(l):\n",
+ " c[i][j] = 0\n",
+ " for k in xrange(n):\n",
+ " c[i][j] = c[i][j] + a[i][k] * b[k][j]\n",
+ " \n",
+ "m = int(raw_input(\"\\nEnter order of A matrix (m x n) : \"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "\n",
+ "a = [[0 for i in range(0,10)]for i in range(0,10)]\n",
+ "b = [[0 for i in range(0,10)]for i in range(0,10)]\n",
+ "c = [[0 for i in range(0,10)]for i in range(0,10)]\n",
+ "\n",
+ "#Read matrices\n",
+ "print \"\\nEnter A matrix values\\n\"\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "n = int(raw_input(\"\\nEnter order of B matrix (n x l) : \"))\n",
+ "l = int(raw_input(\"\"))\n",
+ "\n",
+ "print \"\\nEnter B matrix values\\n\"\n",
+ "for i in range(0,n):\n",
+ " for j in range(0,l):\n",
+ " b[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "matmul()\n",
+ "\n",
+ "print \"\\nResultant matrix is \\n\"\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,l):\n",
+ " sys.stdout.write(\"%5d\"%(c[i][j]))\n",
+ " sys.stdout.write(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter order of A matrix (m x n) : 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter A matrix values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter order of B matrix (n x l) : 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter B matrix values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Resultant matrix is \n",
+ "\n",
+ " 4 14\n",
+ " 16 -20\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 16, Page Number: FNC-31"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "at = [[0,0],[0,0],[0,0]]\n",
+ "\n",
+ "def transpose():\n",
+ " for i in xrange(m):\n",
+ " for j in xrange(n):\n",
+ " at[j][i] = a[i][j] \n",
+ " \n",
+ "m = int(raw_input(\"\\nHow many rows and columns ?\"))\n",
+ "n = int(raw_input(\"\"))\n",
+ "\n",
+ "print \"\\nEnter the matrix values\\n\"\n",
+ "for i in range(0,m):\n",
+ " for j in range(0,n):\n",
+ " a[i][j] = int(raw_input(\"\"))\n",
+ "\n",
+ "transpose()\n",
+ "\n",
+ "print \"\\nTranspose of the matrix is \\n\"\n",
+ "for i in xrange(n):\n",
+ " for j in xrange(m):\n",
+ " sys.stdout.write(\"%5d\"%(at[i][j]))\n",
+ " sys.stdout.write(\"\\n\")"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many rows and columns ?2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the matrix values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "6\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Transpose of the matrix is \n",
+ "\n",
+ " -3 3\n",
+ " 6 2\n",
+ " 0 8\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 17, Page Number: FNC-32"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "\n",
+ "\n",
+ "def sort():\n",
+ " for i in xrange(n):\n",
+ " for j in range(i+1,n):\n",
+ " if x[i] > x[j]:\n",
+ " temp = x[i]\n",
+ " x[i] = x[j]\n",
+ " x[j] = temp\n",
+ " \n",
+ "x = [0 for i in range(0,50)]\n",
+ "n = int(raw_input(\"\\nHow many numbers ? \"))\n",
+ "print \"\\nEnter the list of values\\n\"\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " x[i] = int(raw_input(\"\"))\n",
+ "\n",
+ "sort()\n",
+ "\n",
+ "print \"\\nThe sorted list is\\n\"\n",
+ "\n",
+ "for i in xrange(n):\n",
+ " sys.stdout.write(\"%5d\"%(x[i]))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "How many numbers ? 4\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter the list of values\n",
+ "\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "32\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "-10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "20\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "The sorted list is\n",
+ "\n",
+ " -10 5 20 32"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter14.png b/A_First_course_in_Programming_with_C/screenshots/chapter14.png
new file mode 100755
index 00000000..b3709cd3
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/screenshots/chapter14.png
Binary files differ
diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter5.png b/A_First_course_in_Programming_with_C/screenshots/chapter5.png
new file mode 100755
index 00000000..9286810e
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/screenshots/chapter5.png
Binary files differ
diff --git a/A_First_course_in_Programming_with_C/screenshots/chapter9.png b/A_First_course_in_Programming_with_C/screenshots/chapter9.png
new file mode 100755
index 00000000..8ea89675
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/screenshots/chapter9.png
Binary files differ