{"id":12045,"date":"2021-09-30T15:00:51","date_gmt":"2021-09-30T09:30:51","guid":{"rendered":"https:\/\/python-programs.com\/?p=12045"},"modified":"2021-11-22T18:34:27","modified_gmt":"2021-11-22T13:04:27","slug":"python-program-to-print-the-pyramid-of-horizontal-number-tables","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-the-pyramid-of-horizontal-number-tables\/","title":{"rendered":"Python Program to Print the Pyramid of Horizontal Number Tables"},"content":{"rendered":"
Are you new to the java programming language? We recommend you to ace up your practice session with these Basic Java Programs Examples<\/a><\/p>\n Given the number of rows, the task is to Print the Pyramid of Horizontal Number Tables in C, C++, and Python.<\/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 Pyramid of Horizontal Number Tables in C, C++, and Python.<\/p>\n Approach:<\/strong><\/p>\n 1) Python Implementation<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 2) C++ Implementation<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 3) C Implementation<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n 1) Python Implementation<\/strong><\/p>\n Give the number of rows as user input using int(input()) and store it in a variable.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 2) C++ Implementation<\/strong><\/p>\n Give the number of rows as user input using cin and store it in a variable.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 3) C Implementation<\/strong><\/p>\n Give the number of rows as user input using scanf and store it in a variable.<\/p>\n Below is the implementation<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Are you new to the java programming language? We recommend you to ace up your practice session with these Basic Java Programs Examples Given the number of rows, the task is to Print the Pyramid of Horizontal Number Tables in C, C++, and Python. Examples: Example1: Input: Given number of rows =9 Output: 1 2 …<\/p>\nGiven number of rows =9<\/pre>\n
1 \r\n2 4 \r\n3 6 9 \r\n4 8 12 16 \r\n5 10 15 20 25 \r\n6 12 18 24 30 36 \r\n7 14 21 28 35 42 49 \r\n8 16 24 32 40 48 56 64 \r\n9 18 27 36 45 54 63 72 81<\/pre>\n
Given number of rows =13<\/pre>\n
1 \r\n2 4 \r\n3 6 9 \r\n4 8 12 16 \r\n5 10 15 20 25 \r\n6 12 18 24 30 36 \r\n7 14 21 28 35 42 49 \r\n8 16 24 32 40 48 56 64 \r\n9 18 27 36 45 54 63 72 81 \r\n10 20 30 40 50 60 70 80 90 100 \r\n11 22 33 44 55 66 77 88 99 110 121 \r\n12 24 36 48 60 72 84 96 108 120 132 144 \r\n13 26 39 52 65 78 91 104 117 130 143 156 169<\/pre>\n
Program to Print the Pyramid of Horizontal Number Tables in C, C++, and Python<\/h2>\n
\n
Method #1: Using For loop (Static Input)<\/h3>\n
\n
# Give the number of rows as static input and store it in a variable.\r\nnumberows = 9\r\n# Loop from 1 to the number of rows using For loop.\r\nfor m in range(1, numberows+1):\r\n # Loop from 1 to the number of 1 to parent loop iterator value\r\n # using another For loop(Nested For Loop).\r\n for n in range(1, m+1):\r\n # Print the value of the product of parent loop iterator value\r\n # and inner loop iterator value with space.\r\n print(m*n, end=\" \")\r\n # Print the newline character after the end of the inner For loop.\r\n print()\r\n<\/pre>\n
1 \r\n2 4 \r\n3 6 9 \r\n4 8 12 16 \r\n5 10 15 20 25 \r\n6 12 18 24 30 36 \r\n7 14 21 28 35 42 49 \r\n8 16 24 32 40 48 56 64 \r\n9 18 27 36 45 54 63 72 81<\/pre>\n
#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n \/\/ Give the number of rows as static input and store it\r\n \/\/ in a variable.\r\n int numberows = 9;\r\n\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= numberows; m++) {\r\n \/\/ Loop from 1 to the number of 1 to parent loop\r\n \/\/ iterator value\r\n \/\/ using another For loop(Nested For Loop).\r\n for (int n = 1; n <= m; n++) {\r\n \/\/ Print the value of the product of parent loop\r\n \/\/ iterator value and inner loop iterator value\r\n \/\/ with space.\r\n cout << m * n << \" \";\r\n }\r\n \/\/ Print the newline character after the end of\r\n \/\/ the inner For loop.\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
1 \r\n2 4 \r\n3 6 9 \r\n4 8 12 16 \r\n5 10 15 20 25 \r\n6 12 18 24 30 36 \r\n7 14 21 28 35 42 49 \r\n8 16 24 32 40 48 56 64 \r\n9 18 27 36 45 54 63 72 81<\/pre>\n
#include <stdio.h>\r\n#include <string.h>\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows as static input and store it\r\n \/\/ in a variable.\r\n int numberows = 9;\r\n\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= numberows; m++) {\r\n \/\/ Loop from 1 to the number of 1 to parent loop\r\n \/\/ iterator value\r\n \/\/ using another For loop(Nested For Loop).\r\n for (int n = 1; n <= m; n++) {\r\n \/\/ Print the value of the product of parent loop\r\n \/\/ iterator value and inner loop iterator value\r\n \/\/ with space.\r\n printf(\"%d \", m * n);\r\n }\r\n \/\/ Print the newline character after the end of\r\n \/\/ the inner For loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
1 \r\n2 4 \r\n3 6 9 \r\n4 8 12 16 \r\n5 10 15 20 25 \r\n6 12 18 24 30 36 \r\n7 14 21 28 35 42 49 \r\n8 16 24 32 40 48 56 64 \r\n9 18 27 36 45 54 63 72 81<\/pre>\n
Method #2: Using For loop (User Input)<\/h3>\n
\n
# Give the word as user input using int(input()) and store it in a variable.\r\nnumberows = int(input('Enter some random number of rows = '))\r\n# Loop from 1 to the number of rows using For loop.\r\nfor m in range(1, numberows+1):\r\n # Loop from 1 to the number of 1 to parent loop iterator value\r\n # using another For loop(Nested For Loop).\r\n for n in range(1, m+1):\r\n # Print the value of the product of parent loop iterator value\r\n # and inner loop iterator value with space.\r\n print(m*n, end=\" \")\r\n # Print the newline character after the end of the inner For loop.\r\n print()\r\n<\/pre>\n
Enter some random number of rows = 13\r\n1 \r\n2 4 \r\n3 6 9 \r\n4 8 12 16 \r\n5 10 15 20 25 \r\n6 12 18 24 30 36 \r\n7 14 21 28 35 42 49 \r\n8 16 24 32 40 48 56 64 \r\n9 18 27 36 45 54 63 72 81 \r\n10 20 30 40 50 60 70 80 90 100 \r\n11 22 33 44 55 66 77 88 99 110 121 \r\n12 24 36 48 60 72 84 96 108 120 132 144 \r\n13 26 39 52 65 78 91 104 117 130 143 156 169<\/pre>\n
#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n \/\/ Give the number of rows as user input using cin and\r\n \/\/ store it in a variable.\r\n int numberows;\r\n cin >> numberows;\r\n\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= numberows; m++) {\r\n \/\/ Loop from 1 to the number of 1 to parent loop\r\n \/\/ iterator value\r\n \/\/ using another For loop(Nested For Loop).\r\n for (int n = 1; n <= m; n++) {\r\n \/\/ Print the value of the product of parent loop\r\n \/\/ iterator value and inner loop iterator value\r\n \/\/ with space.\r\n cout << m * n << \" \";\r\n }\r\n \/\/ Print the newline character after the end of\r\n \/\/ the inner For loop.\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
13\r\n1 \r\n2 4 \r\n3 6 9 \r\n4 8 12 16 \r\n5 10 15 20 25 \r\n6 12 18 24 30 36 \r\n7 14 21 28 35 42 49 \r\n8 16 24 32 40 48 56 64 \r\n9 18 27 36 45 54 63 72 81 \r\n10 20 30 40 50 60 70 80 90 100 \r\n11 22 33 44 55 66 77 88 99 110 121 \r\n12 24 36 48 60 72 84 96 108 120 132 144 \r\n13 26 39 52 65 78 91 104 117 130 143 156 169<\/pre>\n
#include <stdio.h>\r\n#include <string.h>\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows as user input using scanf and\r\n \/\/ store it in a variable.\r\n int numberows;\r\n scanf(\"%d\", &numberows);\r\n\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= numberows; m++) {\r\n \/\/ Loop from 1 to the number of 1 to parent loop\r\n \/\/ iterator value\r\n \/\/ using another For loop(Nested For Loop).\r\n for (int n = 1; n <= m; n++) {\r\n \/\/ Print the value of the product of parent loop\r\n \/\/ iterator value and inner loop iterator value\r\n \/\/ with space.\r\n printf(\"%d \", m * n);\r\n }\r\n \/\/ Print the newline character after the end of\r\n \/\/ the inner For loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
13\r\n1 \r\n2 4 \r\n3 6 9 \r\n4 8 12 16 \r\n5 10 15 20 25 \r\n6 12 18 24 30 36 \r\n7 14 21 28 35 42 49 \r\n8 16 24 32 40 48 56 64 \r\n9 18 27 36 45 54 63 72 81 \r\n10 20 30 40 50 60 70 80 90 100 \r\n11 22 33 44 55 66 77 88 99 110 121 \r\n12 24 36 48 60 72 84 96 108 120 132 144 \r\n13 26 39 52 65 78 91 104 117 130 143 156 169<\/pre>\n
\n