{"id":12210,"date":"2021-09-30T15:00:31","date_gmt":"2021-09-30T09:30:31","guid":{"rendered":"https:\/\/python-programs.com\/?p=12210"},"modified":"2021-11-22T18:34:28","modified_gmt":"2021-11-22T13:04:28","slug":"python-program-to-print-number-reduction-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-number-reduction-pattern\/","title":{"rendered":"Python Program to Print Number Reduction Pattern"},"content":{"rendered":"
Don’t miss the chance of Java programs examples with output pdf free download<\/a> as it is very essential for all beginners to experienced programmers for cracking the interviews.<\/p>\n Given the number of rows, the task is to print Number Reduction Pattern 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 Number Reduction Pattern 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 Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews. Given the number of rows, the task is to print Number Reduction Pattern in C, C++, and Python Examples: Example1: Input: Given number of rows = 4 …<\/p>\nGiven number of rows = 4<\/pre>\n
1 2 3 4 \r\n2 3 4 \r\n3 4 \r\n4<\/pre>\n
Given number of rows = 14<\/pre>\n
1 2 3 4 5 6 7 8 9 10 11 12 13 14 \r\n2 3 4 5 6 7 8 9 10 11 12 13 14 \r\n3 4 5 6 7 8 9 10 11 12 13 14 \r\n4 5 6 7 8 9 10 11 12 13 14 \r\n5 6 7 8 9 10 11 12 13 14 \r\n6 7 8 9 10 11 12 13 14 \r\n7 8 9 10 11 12 13 14 \r\n8 9 10 11 12 13 14 \r\n9 10 11 12 13 14 \r\n10 11 12 13 14 \r\n11 12 13 14 \r\n12 13 14 \r\n13 14 \r\n14 \r\n<\/pre>\n
Program to Print Number Reduction Pattern 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\nnumbrrows = 9\r\n# Loop from 0 to the number of rows using For loop.\r\nfor m in range(0, numbrrows+1):\r\n # Loop from iterator value of the parent For loop +1 to\r\n # the number of rows using another for loop(Nested For loop).\r\n for n in range(m + 1, numbrrows+1):\r\n # Print the iterator value of the inner for loop.\r\n print(n, end=' ')\r\n # Print the Newline character after the end of the inner loop.\r\n print()\r\n<\/pre>\n
1 2 3 4 5 6 7 8 9 \r\n2 3 4 5 6 7 8 9 \r\n3 4 5 6 7 8 9 \r\n4 5 6 7 8 9 \r\n5 6 7 8 9 \r\n6 7 8 9 \r\n7 8 9 \r\n8 9 \r\n9<\/pre>\n
#include <iostream>\r\nusing namespace std;\r\n\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 numbrrows = 10;\r\n \/\/ Loop from 0 to the number of rows using For loop.\r\n for (int m = 0; m <= numbrrows; m++) {\r\n \/* Loop from iterator value of the parent For loop+1\r\n to the number of rows using another for\r\n loop(Nested For loop).*\/\r\n for (int n = m + 1; n <= numbrrows; n++) {\r\n \/\/ Print the iterator value of the inner for\r\n \/\/ loop.\r\n cout << n << \" \";\r\n }\r\n \/\/ Print the Newline character after the end of the\r\n \/\/ inner loop.\r\n cout << endl;\r\n }\r\n return 0;\r\n}<\/pre>\n
1 2 3 4 5 6 7 8 9 10 \r\n2 3 4 5 6 7 8 9 10 \r\n3 4 5 6 7 8 9 10 \r\n4 5 6 7 8 9 10 \r\n5 6 7 8 9 10 \r\n6 7 8 9 10 \r\n7 8 9 10 \r\n8 9 10 \r\n9 10 \r\n10<\/pre>\n
#include <stdio.h>\r\n\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 numbrrows = 14;\r\n \/\/ Loop from 0 to the number of rows using For loop.\r\n for (int m = 0; m <= numbrrows; m++) {\r\n \/* Loop from iterator value of the parent For loop+1\r\n to the number of rows using another for\r\n loop(Nested For loop).*\/\r\n for (int n = m + 1; n <= numbrrows; n++) {\r\n \/\/ Print the iterator value of the inner for\r\n \/\/ loop.\r\n printf(\"%d \", n);\r\n }\r\n \/\/ Print the Newline character after the end of the\r\n \/\/ inner loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
1 2 3 4 5 6 7 8 9 10 11 12 13 14 \r\n2 3 4 5 6 7 8 9 10 11 12 13 14 \r\n3 4 5 6 7 8 9 10 11 12 13 14 \r\n4 5 6 7 8 9 10 11 12 13 14 \r\n5 6 7 8 9 10 11 12 13 14 \r\n6 7 8 9 10 11 12 13 14 \r\n7 8 9 10 11 12 13 14 \r\n8 9 10 11 12 13 14 \r\n9 10 11 12 13 14 \r\n10 11 12 13 14 \r\n11 12 13 14 \r\n12 13 14 \r\n13 14 \r\n14 \r\n<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
# Give the number of rows as user input using int(input()) and store it in a variable.\r\nnumbrrows = int(input('Enter some random number of rows = '))\r\n# Loop from 0 to the number of rows using For loop.\r\nfor m in range(0, numbrrows+1):\r\n # Loop from iterator value of the parent For loop +1 to\r\n # the number of rows using another for loop(Nested For loop).\r\n for n in range(m + 1, numbrrows+1):\r\n # Print the iterator value of the inner for loop.\r\n print(n, end=' ')\r\n # Print the Newline character after the end of the inner loop.\r\n print()\r\n<\/pre>\n
Enter some random number of rows = 6\r\n1 2 3 4 5 6 \r\n2 3 4 5 6 \r\n3 4 5 6 \r\n4 5 6 \r\n5 6 \r\n6<\/pre>\n
#include <iostream>\r\nusing namespace std;\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows as user input using\r\n \/\/ int(input()) and store it in a variable.\r\n int numbrrows;\r\n cin >> numbrrows;\r\n \/\/ Loop from 0 to the number of rows using For loop.\r\n for (int m = 0; m <= numbrrows; m++) {\r\n \/* Loop from iterator value of the parent For loop+1\r\n to the number of rows using another for\r\n loop(Nested For loop).*\/\r\n for (int n = m + 1; n <= numbrrows; n++) {\r\n \/\/ Print the iterator value of the inner for\r\n \/\/ loop.\r\n cout << n << \" \";\r\n }\r\n \/\/ Print the Newline character after the end of the\r\n \/\/ inner loop.\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
4\r\n1 2 3 4 \r\n2 3 4 \r\n3 4 \r\n4<\/pre>\n
#include <math.h>\r\n#include <stdio.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 numbrrows;\r\n scanf(\"%d\", &numbrrows);\r\n \/\/ Loop from 0 to the number of rows using For loop.\r\n for (int m = 0; m <= numbrrows; m++) {\r\n \/* Loop from iterator value of the parent For loop+1\r\n to the number of rows using another for\r\n loop(Nested For loop).*\/\r\n for (int n = m + 1; n <= numbrrows; n++) {\r\n \/\/ Print the iterator value of the inner for\r\n \/\/ loop.\r\n printf(\"%d \", n);\r\n }\r\n \/\/ Print the Newline character after the end of the\r\n \/\/ inner loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
4\r\n1 2 3 4 \r\n2 3 4 \r\n3 4 \r\n4<\/pre>\n
\n