diff options
Diffstat (limited to 'Fundamental_of_Computing_and_Programming_in_C/Chapter01.ipynb')
-rwxr-xr-x | Fundamental_of_Computing_and_Programming_in_C/Chapter01.ipynb | 578 |
1 files changed, 0 insertions, 578 deletions
diff --git a/Fundamental_of_Computing_and_Programming_in_C/Chapter01.ipynb b/Fundamental_of_Computing_and_Programming_in_C/Chapter01.ipynb deleted file mode 100755 index 8e50e4de..00000000 --- a/Fundamental_of_Computing_and_Programming_in_C/Chapter01.ipynb +++ /dev/null @@ -1,578 +0,0 @@ -{ - "metadata": { - "name": "", - "signature": "sha256:e61d5eac9962a1b27acd93d08c5b466532db593eb946c997e161cd14ea1acee1" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 01 : Operators and Expressions" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1: Page No.:4.35" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Usage of Arithmetic operators\n", - "\n", - "#Variable declaration\n", - "i=10\n", - "j=20\n", - "\n", - "#the sum value of variables i and j stores in k variable \n", - "k=i+j\n", - "\n", - "#Result\n", - "print \"Value of k is %d\"%(k)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Value of k is 30\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2: Page No.:4.35" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "# Demonstrations on arithmetic operators\n", - "\n", - "#User Input\n", - "\n", - "a,b,c,d=input(\"Enter values of a, b, c, d: \")\n", - "\n", - "#Calculation\n", - "a+=(b*c)+d\n", - "\n", - "#Result\n", - "print \"Value of a = %d \"%(a)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter values of a, b, c, d ,e: 12,90,56,43\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Value of a = 5095 \n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3: Page No.:4.36" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Find out all arithmetic operation on two given values\n", - "\n", - "#Variable Declaration\n", - "sum=sub=mul=rem=0\n", - "div=0.0\n", - "a=0\n", - "#User Input\n", - "b,c,d=input(\"Enter the values of b, c, d: \")\n", - "\n", - "sum = b + c\n", - "sub = b - c\n", - "mul = b * c\n", - "div = b/c\n", - "rem = b % d\n", - "\n", - "print \"Sum = %d, Sub = %d, Mul = %d, Div = %f\"%(sum,sub,mul,div)\n", - "print \"Remainder of division of b & d is %d\"%(rem)\n", - "print \"a=%d\"%(a)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter the values of b, c, d: 2,6,45\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Sum = 8, Sub = -4, Mul = 12, Div = 0.000000\n", - "Remainder of division of b & d is 2\n", - "a=0\n" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4: Page No.: 4.38" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Program to use various relational operators\n", - "\n", - "#!=,==,>=,<= are assignment operator\n", - "\n", - "print \"Condition : Return values\"\n", - "print \" 5!=5 : %5d\"%(5!=5) \n", - "print \" 5==5 : %5d\"%(5==5)\n", - "print \" 5>=5 : %5d\"%(5>=5)\n", - "print \" 5<=5 : %5d\"%(5<=50)\n", - "print \" 5!=3 : %5d\"%(5!=3)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Condition : Return values\n", - " 5!=5 : 0\n", - " 5==5 : 1\n", - " 5>=5 : 1\n", - " 5<=5 : 1\n", - " 5!=3 : 1\n" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5: Page No.:4.39" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "# Demonstrate of logical operator\n", - "\n", - "#Variable Declaration\n", - "c1=c2=c3=0\n", - "\n", - "#USer Input\n", - "c1,c2,c3=input(\"Enter Values of C1, C2 and C3: \")\n", - "print \"\\n\"\n", - "\n", - "if (c1<c2) and (c1<c3):\n", - " print \"C1 is less than C2 and C3\"\n", - "\n", - "if not(c1) < (c2 ):\n", - " print \"C1 is greater than C2\"\n", - " \n", - "if ((c1 < c2 or c1 < c3)):\n", - " print \"C1 is less than C2 or C3 or both\"\n", - " \n", - "#else:\n", - " # print \"Something went wrong. Check\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter Values of C1, C2 and C3: 45,32,98\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "\n", - "C1 is greater than C2\n", - "C1 is less than C2 or C3 or both\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6: Page No.: 4.40" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Demonstration of assignment operator\n", - "\n", - "#Variable Declaration\n", - "i=4\n", - "j=5\n", - "\n", - "#'=' is assignment operator\n", - "i=j\n", - "k=i\n", - "\n", - "#Result\n", - "print \"K = %d\"%(k)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "K = 5\n" - ] - } - ], - "prompt_number": 44 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7: Page No.:4.42" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Program using Increment and Decrement Operator.\n", - "\n", - "#Variable Declaration\n", - "a=10\n", - "\n", - "#There is no post and pre increment in python\n", - "#There is no post and pre decrement in python\n", - "\n", - "#Result\n", - "print \"The Value of a = %d\"%(a)\n", - "print \"Increment of a = %d\"%(a+1)\n", - "print \"Decrement of a = %d\"%(a-1)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The Value of a = 10\n", - "Increment of a = 11\n", - "Decrement of a = 9\n" - ] - } - ], - "prompt_number": 50 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8: Page No.:4.42" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Program using increment and decrement operators\n", - "\n", - "#Variable Declaration\n", - "\n", - "i=3\n", - "j=4\n", - "\n", - "#No Pre Decrement and Pre Increment in python\n", - "\n", - "i=i+1 #Increment value\n", - "j=j-1 #Decrement value\n", - "\n", - "k=i+j\n", - "\n", - "#Result\n", - "print \"i = %d, j = %d, k = %d\"%(i,j,k)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "i = 4, j = 3, k = 7\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 9: Page No.: 4.46" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Program to illustrate sizeof operator\n", - "\n", - "import sys\n", - "\n", - "num=int(1234567890)\n", - "dec=float(0.123456)\n", - "ext=0.123456789\n", - "ltr='A'\n", - "string=\"Something to write home about....\"\n", - "class struct():\n", - " a=0\n", - "boy=struct()\n", - "\n", - "#Result\n", - "print \"Size of num is in %d bytes.\"%(sys.getsizeof(num))\n", - "print \"Size of dec is in %d bytes.\"%(sys.getsizeof(dec))\n", - "print \"Size of ext double is in %d bytes.\"%(sys.getsizeof(ext))\n", - "print \"Size of ltr char is in %d bytes.\"%(sys.getsizeof(ltr))\n", - "print \"Size of the string is in %d bytes.\"%(sys.getsizeof(string))\n", - "print \"Size of struct is in %d bytes.\"%(sys.getsizeof(struct()))" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Size of num is in 12 bytes.\n", - "Size of dec is in 16 bytes.\n", - "Size of ext double is in 16 bytes.\n", - "Size of ltr char is in 22 bytes.\n", - "Size of the string is in 54 bytes.\n", - "Size of struct is in 32 bytes.\n" - ] - } - ], - "prompt_number": 70 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Case Study 1: PageNo.:4.52" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Convert number of days to months and days\n", - "\n", - "#Variable Declaration\n", - "m=0\n", - "d=0\n", - "\n", - "#User Input\n", - "nd=input(\"Enter the number of days= \")\n", - "\n", - "\n", - "m=nd/30\n", - "d=nd%30\n", - "\n", - "#Result\n", - "print \"Number of months...\", m\n", - "print \"Number of days...\", d" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter the number of days= 215\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Number of months... 7\n", - "Number of days... 5\n" - ] - } - ], - "prompt_number": 74 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Case Study 2: Page No.:4.53" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Calculate Salesman Salary\n", - "\n", - "#Variable Declaration\n", - "BASIC=2500\n", - "BONUS_RATE=200\n", - "COM=0.02\n", - "\n", - "qty=0\n", - "GS=price=Bonus=Comm=0.0\n", - "#User input\n", - "qty,price=input(\"Enter the number of items Sold and Price...: \")\n", - "\n", - "Bonus=BONUS_RATE*qty\n", - "Comm=COM*qty*price\n", - "\n", - "GS=BASIC+Bonus+Comm\n", - "\n", - "print \"Bonus.... %6.2f\"%(Bonus)\n", - "\n", - "print \"Commission.... %6.2f\"%(Comm)\n", - "\n", - "print \"Gross Salary... %6.2f\"%(GS)\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter the number of items Sold and Price...: 10,200\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Bonus.... 2000.00\n", - "Commission.... 40.00\n", - "Gross Salary... 4540.00\n" - ] - } - ], - "prompt_number": 75 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Case Study 3: Page No.:4.54" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Post increment using different storage classes\n", - "\n", - "#Defining function\n", - "def postinc():\n", - " x=1\n", - " print \"X = %d\" %(x)\n", - " x=x+1\n", - " \n", - "#Call Function\n", - "postinc()\n", - "postinc()\n", - "postinc()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "X = 1\n", - "X = 1\n", - "X = 1\n" - ] - } - ], - "prompt_number": 77 - } - ], - "metadata": {} - } - ] -}
\ No newline at end of file |