{"id":12151,"date":"2021-09-30T15:00:37","date_gmt":"2021-09-30T09:30:37","guid":{"rendered":"https:\/\/python-programs.com\/?p=12151"},"modified":"2021-11-22T18:34:27","modified_gmt":"2021-11-22T13:04:27","slug":"python-program-to-print-reverse-number-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-reverse-number-pattern\/","title":{"rendered":"Python Program to Print Reverse Number Pattern"},"content":{"rendered":"
Our website provided core java programs examples with output<\/a> aid beginners and expert coders to test their knowledge gap and learn accordingly.<\/p>\n Given the number of rows, the task is to print Reverse Number 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 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 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 Our website provided core java programs examples with output aid beginners and expert coders to test their knowledge gap and learn accordingly. Given the number of rows, the task is to print Reverse Number Pattern in C, C++, and Python. Examples: Example1: Input: Given number of rows = 7 Output: 7 6 5 4 3 …<\/p>\nGiven number of rows = 7<\/pre>\n
7 6 5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n5 4 3 2 1 \r\n4 3 2 1 \r\n3 2 1 \r\n2 1 \r\n1<\/pre>\n
Given number of rows = 10<\/pre>\n
10 9 8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n5 4 3 2 1 \r\n4 3 2 1 \r\n3 2 1 \r\n2 1 \r\n1<\/pre>\n
Program to Print Reverse Number 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 = 7\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 the number of rows - iterator value of the first parent For loop to 0\r\n # in decreasing order using another For loop(Nested For loop).\r\n for n in range(numbrrows - m, 0, -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
7 6 5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n5 4 3 2 1 \r\n4 3 2 1 \r\n3 2 1 \r\n2 1 \r\n1<\/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 the number of rows - iterator value of\r\n \/\/ the first parent For loop to 0 in decreasing\r\n \/\/ order using another For loop(Nested For loop).\r\n for (int n = numbrrows - m; n > 0; 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
10 9 8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n5 4 3 2 1 \r\n4 3 2 1 \r\n3 2 1 \r\n2 1 \r\n1<\/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 = 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 the number of rows - iterator value of\r\n \/\/ the first parent For loop to 0 in decreasing\r\n \/\/ order using another For loop(Nested For loop).\r\n for (int n = numbrrows - m; n > 0; 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
10\r\n10 9 8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n5 4 3 2 1 \r\n4 3 2 1 \r\n3 2 1 \r\n2 1 \r\n1<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\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 the number of rows - iterator value of the first parent For loop to 0\r\n # in decreasing order using another For loop(Nested For loop).\r\n for n in range(numbrrows - m, 0, -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 = 11\r\n11 10 9 8 7 6 5 4 3 2 1 \r\n10 9 8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n5 4 3 2 1 \r\n4 3 2 1 \r\n3 2 1 \r\n2 1 \r\n1<\/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 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 the number of rows - iterator value of\r\n \/\/ the first parent For loop to 0 in decreasing\r\n \/\/ order using another For loop(Nested For loop).\r\n for (int n = numbrrows - m; n > 0; 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
10\r\n10 9 8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n5 4 3 2 1 \r\n4 3 2 1 \r\n3 2 1 \r\n2 1 \r\n1<\/pre>\n
#include <stdio.h>\r\n\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 the number of rows - iterator value of\r\n \/\/ the first parent For loop to 0 in decreasing\r\n \/\/ order using another For loop(Nested For loop).\r\n for (int n = numbrrows - m; n > 0; 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
10\r\n10 9 8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n5 4 3 2 1 \r\n4 3 2 1 \r\n3 2 1 \r\n2 1 \r\n1<\/pre>\n
\n