summaryrefslogtreecommitdiff
path: root/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter11.ipynb
blob: ce091d42607f9c191e0757cc7236425078832e41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{
 "metadata": {
  "name": "",
  "signature": "sha256:74e91fb616db3aa96bac711fa075c7c19a951b52d2e8ba98c61929ac216b2aca"
 },
 "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 maxmin.c, Page 250"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "N=10\n",
      "def max_min(a,n): #function definition\n",
      "    max=a[0]\n",
      "    min=a[0]\n",
      "    for i in range(n-1): #calculating max and min from list\n",
      "        if(a[i+1]>max):\n",
      "            max=a[i+1]\n",
      "        elif(a[i+1]<min):\n",
      "            min=a[i+1]\n",
      "    return (max,min)\n",
      "li=raw_input(\"Enter %d numbers: \" % N) #input of numbers from user\n",
      "b=map(int, li.split())\n",
      "big,small=max_min(b,N) #call function to calculate max and min\n",
      "print \"Largest: %d\"%big #print max and min\n",
      "print \"Smallest: %d\"%small\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Largest: 102\n",
        "Smallest: 7\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}