{"id":12146,"date":"2021-09-30T15:00:30","date_gmt":"2021-09-30T09:30:30","guid":{"rendered":"https:\/\/python-programs.com\/?p=12146"},"modified":"2021-11-22T18:34:28","modified_gmt":"2021-11-22T13:04:28","slug":"python-program-to-print-reverse-pyramid-of-numbers","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-reverse-pyramid-of-numbers\/","title":{"rendered":"Python Program to Print Reverse Pyramid of Numbers"},"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 of the pyramid, the task is to print a Reverse Pyramid of Numbers 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 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 of the pyramid, the task is to print a Reverse Pyramid of Numbers in C, C++, and Python. Examples: Example1: Input: Given number of rows = 10 …<\/p>\nGiven number of rows = 10<\/pre>\n
1 \r\n2 1 \r\n3 2 1 \r\n4 3 2 1 \r\n5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1<\/pre>\n
Given number of rows = 6<\/pre>\n
1 \r\n2 1 \r\n3 2 1 \r\n4 3 2 1 \r\n5 4 3 2 1<\/pre>\n
Program to Print Reverse Pyramid of Numbers 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 = 10\r\n# Loop from 1 to the number of rows using For loop.\r\nfor m in range(1, numbrrows):\r\n # Loop from the parent loop iterator value to 0 in decreasing order\r\n # using another For loop(Nested For Loop).\r\n for n in range(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
1 \r\n2 1 \r\n3 2 1 \r\n4 3 2 1 \r\n5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1<\/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 1 to the number of rows using For loop.\r\n for (int m = 1; m < numbrrows; m++) {\r\n \/\/ Loop from the parent loop iterator value to 0 in\r\n \/\/ decreasing order using another For loop(Nested\r\n \/\/ For Loop).\r\n for (int n = 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
1 \r\n2 1 \r\n3 2 1 \r\n4 3 2 1 \r\n5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1<\/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 1 to the number of rows using For loop.\r\n for (int m = 1; m < numbrrows; m++) {\r\n \/\/ Loop from the parent loop iterator value to 0 in\r\n \/\/ decreasing order using another For loop(Nested\r\n \/\/ For Loop).\r\n for (int n = 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
1 \r\n2 1 \r\n3 2 1 \r\n4 3 2 1 \r\n5 4 3 2 1 \r\n6 5 4 3 2 1 \r\n7 6 5 4 3 2 1 \r\n8 7 6 5 4 3 2 1 \r\n9 8 7 6 5 4 3 2 1<\/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 1 to the number of rows using For loop.\r\nfor m in range(1, numbrrows):\r\n # Loop from the parent loop iterator value to 0 in decreasing order\r\n # using another For loop(Nested For Loop).\r\n for n in range(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 = 6\r\n1 \r\n2 1 \r\n3 2 1 \r\n4 3 2 1 \r\n5 4 3 2 1<\/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 \/\/ cin and store it in a variable.\r\n int numbrrows;\r\n cin >> numbrrows;\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m < numbrrows; m++) {\r\n \/\/ Loop from the parent loop iterator value to 0 in\r\n \/\/ decreasing order using another For loop(Nested\r\n \/\/ For Loop).\r\n for (int n = 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
6\r\n1 \r\n2 1 \r\n3 2 1 \r\n4 3 2 1 \r\n5 4 3 2 1<\/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 1 to the number of rows using For loop.\r\n for (int m = 1; m < numbrrows; m++) {\r\n \/\/ Loop from the parent loop iterator value to 0 in\r\n \/\/ decreasing order using another For loop(Nested\r\n \/\/ For Loop).\r\n for (int n = 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
6\r\n1 \r\n2 1 \r\n3 2 1 \r\n4 3 2 1 \r\n5 4 3 2 1<\/pre>\n
\n