summaryrefslogtreecommitdiff
path: root/Let_us_C/chapter-7.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Let_us_C/chapter-7.ipynb')
-rw-r--r--Let_us_C/chapter-7.ipynb210
1 files changed, 210 insertions, 0 deletions
diff --git a/Let_us_C/chapter-7.ipynb b/Let_us_C/chapter-7.ipynb
new file mode 100644
index 00000000..9024266b
--- /dev/null
+++ b/Let_us_C/chapter-7.ipynb
@@ -0,0 +1,210 @@
+{
+ "metadata": {
+ "name": "chapter-7..ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 7: The C Preprocessor<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Macro Expansion, Page number: 244<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to illustrate macros'''\n",
+ "\n",
+ "#Macro declaration\n",
+ "UPPER = 25\n",
+ "\n",
+ "for i in range(1,UPPER+1): #macro expansion\n",
+ " print(i)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1\n",
+ "2\n",
+ "3\n",
+ "4\n",
+ "5\n",
+ "6\n",
+ "7\n",
+ "8\n",
+ "9\n",
+ "10\n",
+ "11\n",
+ "12\n",
+ "13\n",
+ "14\n",
+ "15\n",
+ "16\n",
+ "17\n",
+ "18\n",
+ "19\n",
+ "20\n",
+ "21\n",
+ "22\n",
+ "23\n",
+ "24\n",
+ "25\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Macro Definition, Page number: 244<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to illustrate macros'''\n",
+ "\n",
+ "#Macro declaration\n",
+ "PI = 3.1415\n",
+ "\n",
+ "#Variable declaration\n",
+ "r = 6.25 \n",
+ "\n",
+ "#Calculation\n",
+ "area = PI * r * r\n",
+ "\n",
+ "#Result\n",
+ "print \"Area of circle = \", area \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of circle = 122.71484375\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Macros with Arguments, Page number: 248<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to illustrate macros with arguments'''\n",
+ "\n",
+ "#Macro declaration\n",
+ "def AREA(x): #define AREA(x) ( 3.14 * x * x )\n",
+ " return(3.14 * x * x )\n",
+ "\n",
+ "#Variable declaration\n",
+ "r1 = 6.25\n",
+ "r2 = 2.5\n",
+ "\n",
+ "#Result\n",
+ "a = AREA(r1)\n",
+ "print \"Area of circle = \", a \n",
+ "a = AREA(r2) \n",
+ "print \"Area of circle = \", a\n",
+ " \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area of circle = 122.65625\n",
+ "Area of circle = 19.625\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Macros with Arguments, Page number: 249<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to illustrate macros with arguments'''\n",
+ "\n",
+ "#Macro declaration\n",
+ "def ISDIGIT(y): #define ISDIGIT(y) ( y >= 48 && y <= 57 )\n",
+ " return( y >= 48 and y <= 57 )\n",
+ "\n",
+ "#Input from user\n",
+ "#ch = raw_input(\"Enter any digit \")\n",
+ "ch = 'a'\n",
+ "\n",
+ "#Result\n",
+ "if ISDIGIT ( ch ):\n",
+ " print \"You entered a digit\" \n",
+ "else:\n",
+ " print \"Illegal input\" \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Illegal input\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file