summaryrefslogtreecommitdiff
path: root/Fundamental_of_Computing_and_Programming_in_C/Chapter02.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Fundamental_of_Computing_and_Programming_in_C/Chapter02.ipynb')
-rwxr-xr-xFundamental_of_Computing_and_Programming_in_C/Chapter02.ipynb767
1 files changed, 0 insertions, 767 deletions
diff --git a/Fundamental_of_Computing_and_Programming_in_C/Chapter02.ipynb b/Fundamental_of_Computing_and_Programming_in_C/Chapter02.ipynb
deleted file mode 100755
index 1aa8a278..00000000
--- a/Fundamental_of_Computing_and_Programming_in_C/Chapter02.ipynb
+++ /dev/null
@@ -1,767 +0,0 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:e63878167c3dee16dba0cb7cf1eb45b07d3e347ca99ab3a68339c448d68bdb66"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 02 : Managing Input and Output Operators"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 1, Page No 4.56"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Testing Characters\n",
- "\n",
- "#Variable Declaration\n",
- "ch=''\n",
- "\n",
- "#User Input\n",
- "ch=raw_input(\"Give any Character as a input: \")\n",
- "\n",
- "if (ch.isalpha()>0): #Checking whether the character is alphabet\n",
- " print ch,\"is a alphabet\"\n",
- " \n",
- "elif(ch.isdigit()>0): #Checking whether the character is digit\n",
- " print ch,\"is a digit\"\n",
- " \n",
- "else: #else print alphanumeric\n",
- " print ch,\"is a alphanumeric\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give any Character as a input: a\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "a is a alphabet\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 2, Page No 4.57"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Convert Uppercase to Lowercase and Viceversa\n",
- "\n",
- "#Variable Declaration\n",
- "\n",
- "ch=''\n",
- "\n",
- "\n",
- "#User Input\n",
- "ch= raw_input(\"Give the input in lower case or upper case: \")\n",
- "\n",
- "if(ch.islower()): #Converting lowercase if input is uppercase\n",
- " print ch.upper(), \"is a upper case character\"\n",
- " \n",
- "else: #else print lowercase\n",
- " print ch.lower(), \"is a lower case character\"\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give the input in lower case or upper case: s\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "S is a upper case character\n"
- ]
- }
- ],
- "prompt_number": 2
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3, Page No 4.58"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Program using input function\n",
- "\n",
- "scientist=''\n",
- "\n",
- "scientist = raw_input(\"Enter Name: \")\n",
- "print \"Print the name: \", scientist\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter Name: Abdul kalam\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Print the name: Abdul kalam\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 4, Page No 4.62"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Count numbers of entered numbers\n",
- "\n",
- "#Variable declaration\n",
- "i=0\n",
- "j=10\n",
- "k=0\n",
- "\n",
- "#getting input from user \n",
- "j=int(raw_input(\"Give input for j \"))\n",
- "k=int(raw_input(\"Give input for k \"))\n",
- "i=int(raw_input(\"Give input for i \"))\n",
- "\n",
- "i= i, j, k #assigning the user input in to a variable\n",
- "\n",
- "#Result\n",
- "print \"No. of given input values:\", len(i) #counting length of the given input\n",
- "print \"The Value of j and k is \", j, k #printing the values of input"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give input for j 56\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give input for k 32\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give input for i 10\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "No. of given input values: 3\n",
- "The Value of j and k is 56 32\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 5, Page No 4.65"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Print a statement using print\n",
- "\n",
- "print \"VRB Publishers\" #Printing statement"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "VRB Publishers\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 6, Page No 4.65"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Adding two numbers\n",
- "\n",
- "#variable declaration\n",
- "\n",
- "a=6\n",
- "b=8\n",
- "c= a+b #Adding a, b and stores in c \n",
- "\n",
- "#Result\n",
- "print \"Addition of two numbers is : \", c"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Addition of two numbers is : 14\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 7, Page No 4.66"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Reading and Displaying Details of a student\n",
- "\n",
- "#Variable Declaration\n",
- "\n",
- "sno=m1=m2=m3=0\n",
- "name=['20']\n",
- "total=0\n",
- "avg=0.0\n",
- "\n",
- "#User Inputs\n",
- "sno=int(raw_input(\"Give Student serial no. \"))\n",
- "name=raw_input(\"Student Name : \")\n",
- "m1=int(raw_input(\"Student Mark 1: \"))\n",
- "m2=int(raw_input(\"Student Mark 2: \"))\n",
- "m3=int(raw_input(\"Student Mark 3: \"))\n",
- "\n",
- "total=float(m1+m2+m3) #Calculation of marks\n",
- "\n",
- "avg=\"%.2f\"%float(total/3.0) #Average\n",
- "\n",
- "#Result\n",
- "print '\\n'\"Student serial No.:\", sno\n",
- "print \"Student Name:\", name\n",
- "print \"Student's Marks:\", m1, m2, m3\n",
- "print \"Total:\", total\n",
- "print \"Average:\", avg "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give Student serial no. 1\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Student Name : Raja\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Student Mark 1: 90\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Student Mark 2: 95\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Student Mark 3: 98\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\n",
- "Studnt serial No.: 1\n",
- "Student Name: Raja\n",
- "Student's Marks: 90 95 98\n",
- "Total: 283.0\n",
- "Average: 94.33\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 8, Page No:4.71"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Display quotient and reminder of given input\n",
- "\n",
- "#variable declaration\n",
- "\n",
- "a=b=q=r=0\n",
- "\n",
- "#User input\n",
- "a=int(raw_input(\"Give input for a: \"))\n",
- "b=int(raw_input(\"Give input for b: \"))\n",
- "\n",
- "q=float(a/b) #Calculation for Quotient\n",
- "\n",
- "r=float(a-q*b) #Calculation for Reminder\n",
- "\n",
- "#Result\n",
- "print \"Quotient of a and b is :\",q\n",
- "print \"Reminder of a and b is :\",r"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give input for a: 39\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give input for b: 7\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Quotient of a and b is : 5.0\n",
- "Reminder of a and b is : 4.0\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 9, Page No:4.73"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Slope and Midpoint of a line\n",
- "\n",
- "#Variable declaration\n",
- "\n",
- "x=x1=y1=x2=y2=slope=0.0\n",
- "\n",
- "#User input1\n",
- "\n",
- "x1=int(raw_input(\"Give point X1: \"))\n",
- "y1=int(raw_input(\"Give point Y1: \"))\n",
- "\n",
- "\n",
- "#User input2\n",
- "\n",
- "x2=int(raw_input('\\n'\"Give point X2: \"))\n",
- "y2=int(raw_input(\"Give point Y2: \"))\n",
- "\n",
- "slope =(y2-y1)/(x2-x1) #Calculation for Slope\n",
- "\n",
- "#Calculation for Midpoints\n",
- "x=float(x1+x2)/2.0\n",
- "y=float(y1+y2)/2.0\n",
- "\n",
- "#Result\n",
- "print '\\n' \"Slope of a line is :\", slope\n",
- "print \"Midpoint of a line is :\", x,y"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give point X1: 10\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give point Y1: 20\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\n",
- "Give point X2: 30\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give point Y2: 40\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\n",
- "Slope of a line is : 1\n",
- "Midpoint of a line is : 20.0 30.0\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 10, Page No:4.73"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Average of Given N Numbers\n",
- "\n",
- "#Variable Declaration\n",
- "n=0.0\n",
- "x=0\n",
- "total=0\n",
- "avg=0.0\n",
- "\n",
- "#UserInput\n",
- "\n",
- "n=int(raw_input(\"Give total number of input: \"))\n",
- "\n",
- "print \"Give those\",n ,\"Numbers\"\n",
- "\n",
- "for i in range(n): #Looping values of n\n",
- " i=1\n",
- " x=input() #Values for n\n",
- " total+=x # Adding given numbers\n",
- " \n",
- "avg=float(total/n) #Calculating an average of given numbers\n",
- "\n",
- "#Result\n",
- "print \"Sum of given numbers is \", total\n",
- "print \"Average is \", avg\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give total number of input: 5\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Give those 5 Numbers\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "17\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "7\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "76\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "3\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "9\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Sum of given numbers is 112\n",
- "Average is 22.0\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 11, Page No:4.75"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Temperature Conversion (Fahrenheit to Celsius)\n",
- "\n",
- "#Variable Declaration\n",
- "\n",
- "F_MIN =0\n",
- "F_MAX=500\n",
- "INC=50\n",
- "fh= F_MIN\n",
- "\n",
- "print \"Fahrenheit\" '\\t' \"Celsius\"\n",
- "while(fh<=F_MAX):\n",
- " cel =\"%.2f\"%float((fh-(32.0))/1.8) #Calculating Celsius value\n",
- " print fh,'\\t''\\t', cel\n",
- " fh=fh+INC #Calculating Fahrenheit value\n",
- " "
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Fahrenheit\tCelsius\n",
- "0 \t\t-17.78\n",
- "50 \t\t10.00\n",
- "100 \t\t37.78\n",
- "150 \t\t65.56\n",
- "200 \t\t93.33\n",
- "250 \t\t121.11\n",
- "300 \t\t148.89\n",
- "350 \t\t176.67\n",
- "400 \t\t204.44\n",
- "450 \t\t232.22\n",
- "500 \t\t260.00\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 12, Page No:4.76"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "#Area of Triangle\n",
- "\n",
- "#Variable Declaration\n",
- "\n",
- "a=b=c=s=area=0.0\n",
- "\n",
- "#User input\n",
- "\n",
- "a=int(raw_input(\"First side of Triangle is \"))\n",
- "b=int(raw_input(\"Second side of Triangle is \"))\n",
- "c=int(raw_input(\"Third side of Triangle is \"))\n",
- "\n",
- "s=(a+b+c)/2.0 #Calculating Size of triangle\n",
- "\n",
- "area=\"%.3f\"%float((s*(s-a)*(s-b)*(s-c)) ** 0.5) #Calculating Area of triangle\n",
- "\n",
- "#Result\n",
- "print '\\n',\"Area of Triangle is\",area"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "First side of Triangle is 10\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Second side of Triangle is 10\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Third side of Triangle is 10\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\n",
- "Area of Triangle is 43.301\n"
- ]
- }
- ],
- "prompt_number": 11
- }
- ],
- "metadata": {}
- }
- ]
-} \ No newline at end of file