{"id":20413,"date":"2021-09-11T15:38:23","date_gmt":"2021-09-11T10:08:23","guid":{"rendered":"https:\/\/python-programs.com\/?p=20413"},"modified":"2021-11-22T18:36:21","modified_gmt":"2021-11-22T13:06:21","slug":"python-program-to-print-multiplication-table-using-recursion","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-multiplication-table-using-recursion\/","title":{"rendered":"Python Program to Print Multiplication Table using Recursion"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find Sum of Even Numbers Using Recursion in a List\/Array<\/a><\/p>\n Given a number and the task is to print the multiplication table of that number using recursion in python.<\/p>\n Recursion:<\/strong><\/p>\n Recursion is the process by which a function calls itself directly or indirectly, and the associated function is known as a recursive function. Certain issues can be addressed fairly easily using a recursive approach. Towers of Hanoi (TOH), Inorder \/Preorder\/Postorder Tree Traversals, DFS of Graph, and other analogous issues are examples.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print the multiplication table of the given number using recursion in python:<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n The best way to learn Python for Beginners is to practice as much as they can taking help of the Sample Python Programs For Beginners<\/a>. Using them you can develop code on your own and master coding skills.<\/p>\n In the previous article, we have discussed Python Program to Find Sum of Even Numbers Using Recursion in a List\/Array Given a number and the task is to print the multiplication table of that number using recursion in python. Recursion: Recursion is the process by which a function calls itself directly or indirectly, and the …<\/p>\nGiven Number = 5<\/pre>\n
The Multiplication Table of the above given number 5 :\r\n5 X 1 = 5\r\n5 X 2 = 10\r\n5 X 3 = 15\r\n5 X 4 = 20\r\n5 X 5 = 25\r\n5 X 6 = 30\r\n5 X 7 = 35\r\n5 X 8 = 40\r\n5 X 9 = 45\r\n5 X 10 = 50<\/pre>\n
Given Number = 2<\/pre>\n
The Multiplication Table of the above given number 2 :\r\n2 X 1 = 2\r\n2 X 2 = 4\r\n2 X 3 = 6\r\n2 X 4 = 8\r\n2 X 5 = 10\r\n2 X 6 = 12\r\n2 X 7 = 14\r\n2 X 8 = 16\r\n2 X 9 = 18\r\n2 X 10 = 20<\/pre>\n
Program to Print Multiplication Table using Recursion in Python<\/h2>\n
\n
Method #1: Using Recursion (Static Input)<\/h3>\n
\n
# Create a recursive function to say Mult_table_num which takes the given number and k\r\n# as the arguments and returns the multiplication table of the given number\r\n# using recursion.\r\n\r\n\r\ndef Mult_table_num(gven_numb, k):\r\n # Print the given number multiplied by k.\r\n print(gven_numb, \" X \", k, \" = \", gven_numb * k)\r\n # Check if the k value is less than 10 using the if conditional statement.\r\n if (k < 10):\r\n # If the statement is true, then pass the given number and k+1 value as the arguments\r\n # to the Mult_table_num function.{Recursive Logic}\r\n Mult_table_num(gven_numb, k + 1)\r\n\r\n\r\n# Give the number as static input and store it in a variable.\r\ngven_numb = 5\r\n# Print the multiplication table of the given number using recursion.\r\nprint(\"The Multiplication Table of the above given number \", gven_numb, \":\")\r\n# Pass the given number and 1 as the arguments to the Mult_table_num function.\r\nMult_table_num(gven_numb, 1)\r\n<\/pre>\n
The Multiplication Table of the above given number 5 :\r\n5 X 1 = 5\r\n5 X 2 = 10\r\n5 X 3 = 15\r\n5 X 4 = 20\r\n5 X 5 = 25\r\n5 X 6 = 30\r\n5 X 7 = 35\r\n5 X 8 = 40\r\n5 X 9 = 45\r\n5 X 10 = 50<\/pre>\n
Method #2: Using Recursion (User Input)<\/h3>\n
\n
# Create a recursive function to say Mult_table_num which takes the given number and k\r\n# as the arguments and returns the multiplication table of the given number\r\n# using recursion.\r\n\r\n\r\ndef Mult_table_num(gven_numb, k):\r\n # Print the given number multiplied by k.\r\n print(gven_numb, \" X \", k, \" = \", gven_numb * k)\r\n # Check if the k value is less than 10 using the if conditional statement.\r\n if (k < 10):\r\n # If the statement is true, then pass the given number and k+1 value as the arguments\r\n # to the Mult_table_num function.{Recursive Logic}\r\n Mult_table_num(gven_numb, k + 1)\r\n\r\n\r\n# Give the number as user input using the int(input()) function and\r\n# store it in a variable.\r\ngven_numb = int(input(\"Enter some Random Number = \"))\r\n# Print the multiplication table of the given number using recursion.\r\nprint(\"The Multiplication Table of the above given number \", gven_numb, \":\")\r\n# Pass the given number and 1 as the arguments to the Mult_table_num function.\r\nMult_table_num(gven_numb, 1)\r\n<\/pre>\n
Enter some Random Number = 10\r\nThe Multiplication Table of the above given number 10 :\r\n10 X 1 = 10\r\n10 X 2 = 20\r\n10 X 3 = 30\r\n10 X 4 = 40\r\n10 X 5 = 50\r\n10 X 6 = 60\r\n10 X 7 = 70\r\n10 X 8 = 80\r\n10 X 9 = 90\r\n10 X 10 = 100<\/pre>\n
\n