Difference between revisions of "BASH/C3/Recursive-function/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 13: Line 13:
 
|-
 
|-
 
| 00:10
 
| 00:10
| '''What is a Recursive''' function
+
| 'what is a Recursive' function
  
 
|-
 
|-
Line 53: Line 53:
 
|-
 
|-
 
| 00:52
 
| 00:52
|  '''Recursion''' is a useful technique for simplifying complex algorithms.
+
|  '''Recursion''' is a useful technique for simplifying complex '''algorithm'''s.
  
 
|-
 
|-
Line 69: Line 69:
 
|-
 
|-
 
| 01:10
 
| 01:10
|  '''factorial '''is the '''function''' name.  
+
|  '''factorial() '''is the '''function''' name.  
  
 
|-
 
|-
Line 77: Line 77:
 
|-
 
|-
 
| 01:19
 
| 01:19
|  This statement reads user's '''input''' and stores the value in variable 'n'.
+
|  This statement reads user's '''input''' and stores the '''value''' in variable 'n'.
  
 
|-
 
|-
 
| 01:26
 
| 01:26
|  Here, we have '''if-else condition.'''
+
|  Here, we have ''''if-else' condition.'''
  
 
|-
 
|-
Line 93: Line 93:
 
|-
 
|-
 
| 01:42
 
| 01:42
|  Here is the '''else '''part of the '''if '''statement.
+
|  Here is the ''''else' '''part of the ''''if' '''statement.
  
 
|-
 
|-
 
| 01:46
 
| 01:46
| It calls the '''factorial function.'''
+
| It calls the ''''factorial' function.'''
  
 
|-
 
|-
 
| 01:50
 
| 01:50
| And '''fi '''is the end of the '''if-else''' statement.
+
| And ''''fi' '''is the end of the ''''if-else'''' statement.
  
 
|-
 
|-
 
| 01:55
 
| 01:55
| Let us '''run''' the file''' factorial.sh.'''
+
| Let us '''run''' the file "factorial.sh".  
  
 
|-
 
|-
 
| 01:59
 
| 01:59
| Open the '''terminal''' using '''CTRL+ALT+T '''keys simultaneously on your keyboard.
+
| Open the '''terminal''' using '''CTRL+ALT''' and '''T '''keys simultaneously on your keyboard.
  
 
|-
 
|-
Line 121: Line 121:
 
|-
 
|-
 
| 02:17
 
| 02:17
| Type '''dot slash factorial.sh'''
+
| Type: '''dot slash factorial.sh'''
  
 
|-
 
|-
Line 129: Line 129:
 
|-
 
|-
 
| 02:24
 
| 02:24
|  We see '''"Enter the number"'''.
+
|  We see '''"Enter the number:" '''.
  
 
|-
 
|-
 
| 02:26
 
| 02:26
| I will enter '''0'''.
+
| I will enter 0.
  
 
|-
 
|-
 
| 02:29
 
| 02:29
|  The output is displayed as:
+
|  The '''output''' is displayed as:
  
 
|-
 
|-
 
| 02:31
 
| 02:31
| '''factorial value of 0 is 1'''
+
| '''"factorial value of 0 is 1"'''.
  
 
|-
 
|-
Line 153: Line 153:
 
|-
 
|-
 
| 02:42
 
| 02:42
| This time, I will enter''' 5 '''.
+
| This time, I will enter 5.
  
 
|-
 
|-
Line 161: Line 161:
 
|-
 
|-
 
| 02:47
 
| 02:47
| '''Inside factorial function.'''
+
| '''"Inside factorial function".'''
  
 
|-
 
|-
 
|  02:51
 
|  02:51
|  Let us add some more logic to the '''factorial function.'''
+
|  Let us add some more logic to the ''''factorial' function.'''
  
 
|-
 
|-
Line 177: Line 177:
 
|-
 
|-
 
| 03:03
 
| 03:03
|  Now let us replace the '''echo statement''' inside the '''factorial function''' with the '''code block'''.
+
|  Now, let us replace the '''echo''' statement "Inside the factorial function" with the '''code block'''.
  
 
|-
 
|-
Line 189: Line 189:
 
|-
 
|-
 
| 03:19
 
| 03:19
|  '''If condition''' checks whether the variable value is equal to '''1'''.
+
''''If'''' condition checks whether the variable value is equal to 1.
  
 
|-
 
|-
Line 205: Line 205:
 
|-
 
|-
 
| 03:37
 
| 03:37
| and stores the result in a variable ''''f'.'''
+
| and stores the result in a variable 'f'.
  
 
|-
 
|-
 
| 03:42
 
| 03:42
|  '''Variable f '''stores the '''output''' of '''factorial function.'''
+
Variable 'f' stores the '''output''' of ''''factorial' function.'''
  
 
|-
 
|-
Line 217: Line 217:
 
|-
 
|-
 
| 03:50
 
| 03:50
|  Value of variable '''f''' and '''temp''' is multiplied and stored in '''f'''.
+
|  Value of variable 'f' and '''temp''' are multiplied and stored in 'f'.
  
 
|-
 
|-
 
| 03:57
 
| 03:57
| Then we '''print''' the value of '''f.'''
+
| Then we '''print''' the value of 'f'.
  
 
|-
 
|-
Line 229: Line 229:
 
|-
 
|-
 
|  04:05
 
|  04:05
|  Now come back to our '''slides.'''
+
|  Now, come back to our '''slides.'''
  
 
|-
 
|-
Line 237: Line 237:
 
|-
 
|-
 
| 04:12
 
| 04:12
| # The value of '''n''' is taken from the user i.e. '''n'''.
+
|The value of 'n' is taken from the user i.e. 'n'.
  
 
|-
 
|-
 
|  04:17
 
|  04:17
| # If the value entered is equal to zero then it prints a message
+
|If the value entered is equal to zero then it prints a message
  
 
|-
 
|-
 
|  04:24
 
|  04:24
| # Else it goes to the function '''factorial'''.
+
|Else it goes to the '''function''' '''factorial'''.
  
 
|-
 
|-
 
|  04:29
 
|  04:29
| # Here, if the value is 'equal to one' then it prints value as 'one'.
+
|Here, if the value is 'equal to one' then it prints value as 'one'.
  
 
|-
 
|-
 
|  04:36
 
|  04:36
| # If not, it makes a '''recursive call''' until the value is equal to one.
+
|If not, it makes a '''recursive call''' until the value is equal to one.
  
 
|-
 
|-
 
|04:44   
 
|04:44   
| # Then, all the values are multiplied and displayed.
+
|Then, all the values are multiplied and displayed.
  
 
|-
 
|-
Line 297: Line 297:
 
|-
 
|-
 
| 05:20
 
| 05:20
|  Let us summarize.  
+
|  Let us summarize.In this tutorial, we learned
 
+
|-
+
|  05:21
+
| In this tutorial, we have learned
+
  
 
|-
 
|-
Line 313: Line 309:
 
|-
 
|-
 
| 05:28
 
| 05:28
|  As an assignment,
+
|  As an assignment,write a program where the '''recursive function''' calculates the sum of 'N' numbers.
 
+
|-
+
|  05:29
+
| write a program where the '''recursive function''' calculates the sum of''' N '''numbers.
+
  
 
|-
 
|-
Line 333: Line 325:
 
|-
 
|-
 
| 05:47
 
| 05:47
|  The Spoken Tutorial Project Team: Conducts workshops using spoken tutorials;
+
|  The Spoken Tutorial Project Team: *Conducts workshops using spoken tutorials;
  
 
|-
 
|-
| 05:53
+
|05:53
| Gives certificates to those who pass an online test.
+
|Gives certificates to those who pass an online test.
  
 
|-
 
|-
Line 361: Line 353:
 
|-
 
|-
 
| 06:29  
 
| 06:29  
| This is Ashwini Patil. signing off.
+
| This is Ashwini Patil, signing off.
  
 
|-
 
|-

Latest revision as of 17:17, 23 March 2017

Time Narration
00:01 Dear friends, welcome to the spoken tutorial on Recursive function.
00:07 In this tutorial, we will learn
00:10 'what is a Recursive' function
00:12 with the help of some examples.
00:15 To follow this tutorial, you should have knowledge of Shell Scripting in BASH.
00:20 If not, for relevant tutorials, please visit our website which is as shown.http://www.spoken-tutorial.org
00:27 For this tutorial, I am using
00:29 Ubuntu Linux 12.04 Operating System
00:33 and GNU BASH version 4.2
00:37 Please note, GNU Bash version 4 or above is recommended for practice.
00:44 Let us see what a recursive function is.
00:48 A recursive function is one which calls itself.
00:52 Recursion is a useful technique for simplifying complex algorithms.
00:59 Let me open a file named factorial.sh.
01:04 I have typed the code in this file.
01:07 This is the shebang line.
01:10 factorial() is the function name.
01:12 Inside this, we print a message “Inside factorial function”.
01:19 This statement reads user's input and stores the value in variable 'n'.
01:26 Here, we have 'if-else' condition.
01:30 If condition checks whether the value of 'n' is equal to zero.
01:36 If True, it will display the message "factorial value of n is 1".
01:42 Here is the 'else' part of the 'if' statement.
01:46 It calls the 'factorial' function.
01:50 And 'fi' is the end of the 'if-else' statement.
01:55 Let us run the file "factorial.sh".
01:59 Open the terminal using CTRL+ALT and T keys simultaneously on your keyboard.
02:07 Type: chmod space plus x space factorial dot sh
02:15 Press Enter.
02:17 Type: dot slash factorial.sh
02:21 Press Enter.
02:24 We see "Enter the number:" .
02:26 I will enter 0.
02:29 The output is displayed as:
02:31 "factorial value of 0 is 1".
02:35 Now press the up-arrow key. Recall the previous command.
02:40 Press Enter.
02:42 This time, I will enter 5.
02:45 Now the output is displayed as:
02:47 "Inside factorial function".
02:51 Let us add some more logic to the 'factorial' function.
02:56 We will calculate the factorial of a number.
03:01 Come back to our code.
03:03 Now, let us replace the echo statement "Inside the factorial function" with the code block.
03:10 Click on Save.
03:13 temp is a variable and stores the value entered by user.
03:19 'If' condition checks whether the variable value is equal to 1.
03:25 If True, it will print 1.
03:29 This is the else part of the if statement.
03:33 This reduces one from the temp variable value
03:37 and stores the result in a variable 'f'.
03:42 Variable 'f' stores the output of 'factorial' function.
03:46 This is a recursive call.
03:50 Value of variable 'f' and temp are multiplied and stored in 'f'.
03:57 Then we print the value of 'f'.
04:00 End of if-else statement and function.
04:05 Now, come back to our slides.
04:08 Let us understand the flow of the program.
04:12 The value of 'n' is taken from the user i.e. 'n'.
04:17 If the value entered is equal to zero then it prints a message
04:24 Else it goes to the function factorial.
04:29 Here, if the value is 'equal to one' then it prints value as 'one'.
04:36 If not, it makes a recursive call until the value is equal to one.
04:44 Then, all the values are multiplied and displayed.
04:49 Now come back to our terminal.
04:52 Press the up-arrow key.
04:54 Recall the previous command ./factorial.sh
04:58 Press Enter.
05:00 Now I will enter 5 as the input value.
05:05 We get the factorial of number 5
05:08 that is 120.
05:11 We can see the flow of the program on terminal. Analyze and trace the flow of the program.
05:18 Come back to our slides.
05:20 Let us summarize.In this tutorial, we learned
05:23 Recursive function
05:25 with the help of some examples.
05:28 As an assignment,write a program where the recursive function calculates the sum of 'N' numbers.
05:36 Watch the video available at the link shown below.
05:39 It summarizes the Spoken-Tutorial project.
05:43 If you do not have good bandwidth, you can download and watch it.
05:47 The Spoken Tutorial Project Team: *Conducts workshops using spoken tutorials;
05:53 Gives certificates to those who pass an online test.
05:58 For more details, please write to contact@spoken-tutorial.org
06:06 Spoken Tutorial project is a part of the Talk to a Teacher project.
06:10 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
06:18 More information on this mission is available at the link shown below. http://spoken-tutorial.org\NMEICT-Intro
06:24 The script has been contributed by FOSSEE and Spoken-Tutorial teams.
06:29 This is Ashwini Patil, signing off.
06:33 Thank you for joining.

Contributors and Content Editors

Gaurav, PoojaMoolya, Pratik kamble, Sandhya.np14