summaryrefslogtreecommitdiff
path: root/Practical_C_Programming/Chapter_4_4.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Practical_C_Programming/Chapter_4_4.ipynb')
-rw-r--r--Practical_C_Programming/Chapter_4_4.ipynb137
1 files changed, 114 insertions, 23 deletions
diff --git a/Practical_C_Programming/Chapter_4_4.ipynb b/Practical_C_Programming/Chapter_4_4.ipynb
index bb8fdf51..8602f989 100644
--- a/Practical_C_Programming/Chapter_4_4.ipynb
+++ b/Practical_C_Programming/Chapter_4_4.ipynb
@@ -1,6 +1,7 @@
{
"metadata": {
- "name": "Chapter 4"
+ "name": "",
+ "signature": "sha256:785237ffc865ddc47952e10309b1bb53ee1543217e833069c02c2afb50bff287"
},
"nbformat": 3,
"nbformat_minor": 0,
@@ -11,25 +12,38 @@
"cell_type": "heading",
"level": 1,
"metadata": {},
- "source": "Chapter 4: Basic declarations and expressions"
+ "source": [
+ "Chapter 4: Basic declarations and expressions"
+ ]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
- "source": "Example 4.1, Page number: 71"
+ "source": [
+ "Example 4.1, Page number: 71"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Example 4.1.py\n# To perform a simple calculation\n\n\n# Variable declaration\nx = (1 + 2) * 4\n\n# Result\nprint ('1 plus 2 multiplied by 4 gives %d' % x)",
+ "input": [
+ "\n",
+ "# Variable declaration\n",
+ "x = (1 + 2) * 4\n",
+ "\n",
+ "# Result\n",
+ "print ('1 plus 2 multiplied by 4 gives %d' % x)"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "1 plus 2 multiplied by 4 gives 12\n"
+ "text": [
+ "1 plus 2 multiplied by 4 gives 12\n"
+ ]
}
],
"prompt_number": 1
@@ -38,19 +52,34 @@
"cell_type": "heading",
"level": 3,
"metadata": {},
- "source": "Example 4.2, Page number: 75"
+ "source": [
+ "Example 4.2, Page number: 75"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Example 4.2.py\n# To calculate the twice and thrice of 15\n\n\n# Variable declaration\nterm = 3 * 5\nterm_2 = 2 * term\nterm_3 = 3 * term\n\n# Result\nprint ('Twice %d is %d' % (term, term_2))\nprint ('Three times %d is %d' % (term, term_3))",
+ "input": [
+ "\n",
+ "# Variable declaration\n",
+ "term = 3 * 5\n",
+ "term_2 = 2 * term\n",
+ "term_3 = 3 * term\n",
+ "\n",
+ "# Result\n",
+ "print ('Twice %d is %d' % (term, term_2))\n",
+ "print ('Three times %d is %d' % (term, term_3))"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Twice 15 is 30\nThree times 15 is 45\n"
+ "text": [
+ "Twice 15 is 30\n",
+ "Three times 15 is 45\n"
+ ]
}
],
"prompt_number": 2
@@ -59,19 +88,35 @@
"cell_type": "heading",
"level": 3,
"metadata": {},
- "source": "Example 4.3, Page number: 77"
+ "source": [
+ "Example 4.3, Page number: 77"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Example 4.3.py\n# To calculate the twice and thrice of 15\n\n\n# Variable declaration\nterm = 3 * 5\nterm_2 = 2 * term\nterm_3 = 3 * term\n\n# Result\nprint ('Twice %d is %d' % (term, term_2))\nprint ('Three times %d is %d' % (term, term_3))",
+ "input": [
+ "\n",
+ "\n",
+ "# Variable declaration\n",
+ "term = 3 * 5\n",
+ "term_2 = 2 * term\n",
+ "term_3 = 3 * term\n",
+ "\n",
+ "# Result\n",
+ "print ('Twice %d is %d' % (term, term_2))\n",
+ "print ('Three times %d is %d' % (term, term_3))"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Twice 15 is 30\nThree times 15 is 45\n"
+ "text": [
+ "Twice 15 is 30\n",
+ "Three times 15 is 45\n"
+ ]
}
],
"prompt_number": 3
@@ -80,19 +125,30 @@
"cell_type": "heading",
"level": 3,
"metadata": {},
- "source": "Example 4.4, Page number: 79"
+ "source": [
+ "Example 4.4, Page number: 79"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Example 4.4.py\n# To determine the value of 1/3\n\n\n# Variable declaration\nanswer = 1/3\n\n# Result\nprint ('The value of 1/3 is %f' % answer)",
+ "input": [
+ "\n",
+ "# Variable declaration\n",
+ "answer = 1/3\n",
+ "\n",
+ "# Result\n",
+ "print ('The value of 1/3 is %f' % answer)"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The value of 1/3 is 0.000000\n"
+ "text": [
+ "The value of 1/3 is 0.000000\n"
+ ]
}
],
"prompt_number": 4
@@ -101,19 +157,29 @@
"cell_type": "heading",
"level": 3,
"metadata": {},
- "source": "Example 4.5, Page number: 80"
+ "source": [
+ "Example 4.5, Page number: 80"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Example 4.5.py\n# To determine the value of 2 + 2\n\n\n# Variable declaration\nanswer = 2 + 2\n\n# Result\nprint ('The answer is %d' % answer)",
+ "input": [
+ "\n",
+ "answer = 2 + 2\n",
+ "\n",
+ "# Result\n",
+ "print ('The answer is %d' % answer)"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The answer is 4\n"
+ "text": [
+ "The answer is 4\n"
+ ]
}
],
"prompt_number": 5
@@ -122,19 +188,31 @@
"cell_type": "heading",
"level": 3,
"metadata": {},
- "source": "Example 4.6, Page number: 80"
+ "source": [
+ "Example 4.6, Page number: 80"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Example 4.6.py\n# To determine the integer equivalent of 7.0/22.0 \n\n\n# Variable declaration\nresult = 7.0/22.0\n\n# Result\nprint ('The result is %d' % result)",
+ "input": [
+ "\n",
+ "\n",
+ "# Variable declaration\n",
+ "result = 7.0/22.0\n",
+ "\n",
+ "# Result\n",
+ "print ('The result is %d' % result)"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The result is 0\n"
+ "text": [
+ "The result is 0\n"
+ ]
}
],
"prompt_number": 6
@@ -143,19 +221,32 @@
"cell_type": "heading",
"level": 3,
"metadata": {},
- "source": "Example 4.7, Page number: 82"
+ "source": [
+ "Example 4.7, Page number: 82"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Example 4.7.py\n# To determine the reverse of 3 characters\n\n\n# Variable declaration\nchar1 = 'A'\nchar2 = 'B'\nchar3 = 'C'\n\n# Result\nprint ('%c%c%c reversed is %c%c%c' % (char1, char2, char3, char3, char2, char1))",
+ "input": [
+ "\n",
+ "# Variable declaration\n",
+ "char1 = 'A'\n",
+ "char2 = 'B'\n",
+ "char3 = 'C'\n",
+ "\n",
+ "# Result\n",
+ "print ('%c%c%c reversed is %c%c%c' % (char1, char2, char3, char3, char2, char1))"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "ABC reversed is CBA\n"
+ "text": [
+ "ABC reversed is CBA\n"
+ ]
}
],
"prompt_number": 7