{"id":11316,"date":"2021-09-30T14:30:37","date_gmt":"2021-09-30T09:00:37","guid":{"rendered":"https:\/\/python-programs.com\/?p=11316"},"modified":"2021-11-22T18:34:31","modified_gmt":"2021-11-22T13:04:31","slug":"python-program-to-print-inverted-right-triangle-of-numbers","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-inverted-right-triangle-of-numbers\/","title":{"rendered":"Python Program to Print Inverted Right Triangle of Numbers"},"content":{"rendered":"
Beginners and experienced programmers can rely on these Best Java Programs Examples<\/a> and code various basic and complex logics in the Java programming language with ease.<\/p>\n Given the number of rows of the Triangle, the task is to Print an Inverted Right Triangle 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 Below are the ways to Print an Inverted Right Triangle of Numbers 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 of the Inverted Right Triangle 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 of the Inverted Right Triangle 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 of the Inverted Right Triangle 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 Beginners and experienced programmers can rely on these Best Java Programs Examples and code various basic and complex logics in the Java programming language with ease. Given the number of rows of the Triangle, the task is to Print an Inverted Right Triangle of Numbers in C, C++, and Python Examples: Example1: Input: given number …<\/p>\ngiven number of rows of the Inverted Right Triangle Pattern =13<\/pre>\n
13 13 13 13 13 13 13 13 13 13 13 13 13 \r\n12 12 12 12 12 12 12 12 12 12 12 12 \r\n11 11 11 11 11 11 11 11 11 11 11 \r\n10 10 10 10 10 10 10 10 10 10 \r\n9 9 9 9 9 9 9 9 9 \r\n8 8 8 8 8 8 8 8 \r\n7 7 7 7 7 7 7 \r\n6 6 6 6 6 6 \r\n5 5 5 5 5 \r\n4 4 4 4 \r\n3 3 3 \r\n2 2 \r\n1<\/pre>\n
given number of rows of the Inverted Right Triangle Pattern =8<\/pre>\n
8 8 8 8 8 8 8 8 \r\n7 7 7 7 7 7 7 \r\n6 6 6 6 6 6 \r\n5 5 5 5 5 \r\n4 4 4 4 \r\n3 3 3 \r\n2 2 \r\n1<\/pre>\n
Program to Print an Inverted Right Triangle 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 of the Inverted Right Triangle as static input and store it in a variable.\r\ntriNumRows = 13\r\n# Loop from the given number of rows to 0 using For loop and take iterator value as m.\r\nfor m in range(triNumRows, -1, -1):\r\n # Loop till the iterator value of the first loop using another nested For loop.\r\n for n in range(m):\r\n # Print the First Loop iterator value that is m and space character.\r\n print(m, end=' ')\r\n # Print the newline character after inner for loop.\r\n print()\r\n<\/pre>\n
13 13 13 13 13 13 13 13 13 13 13 13 13 \r\n12 12 12 12 12 12 12 12 12 12 12 12 \r\n11 11 11 11 11 11 11 11 11 11 11 \r\n10 10 10 10 10 10 10 10 10 10 \r\n9 9 9 9 9 9 9 9 9 \r\n8 8 8 8 8 8 8 8 \r\n7 7 7 7 7 7 7 \r\n6 6 6 6 6 6 \r\n5 5 5 5 5 \r\n4 4 4 4 \r\n3 3 3 \r\n2 2 \r\n1 \r\n<\/pre>\n
#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows of the Inverted Right\r\n \/\/ Triangle as static input and store it in a variable.\r\n int triNumRows = 8;\r\n \/\/ Loop from the given number of rows to 0 using For\r\n \/\/ loop and take iterator value as m.\r\n for (int m = triNumRows; m >= 0; m--) {\r\n\r\n \/\/ Loop till the iterator value of the first loop\r\n \/\/ using another nested For loop.\r\n for (int n = 0; n < m; n++) {\r\n \/\/ Print the First Loop iterator value that is m\r\n \/\/ and space character.\r\n cout << m << \" \";\r\n }\r\n \/\/ Print the newline character after inner for loop.\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
8 8 8 8 8 8 8 8 \r\n7 7 7 7 7 7 7 \r\n6 6 6 6 6 6 \r\n5 5 5 5 5 \r\n4 4 4 4 \r\n3 3 3 \r\n2 2 \r\n1 \r\n<\/pre>\n
#include <stdio.h>\r\n\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows of the Inverted Right\r\n \/\/ Triangle as static input and store it in a variable.\r\n int triNumRows = 8;\r\n \/\/ Loop from the given number of rows to 0 using For\r\n \/\/ loop and take iterator value as m.\r\n for (int m = triNumRows; m >= 0; m--) {\r\n\r\n \/\/ Loop till the iterator value of the first loop\r\n \/\/ using another nested For loop.\r\n for (int n = 0; n < m; n++) {\r\n \/\/ Print the First Loop iterator value that is m\r\n \/\/ and space character.\r\n printf(\"%d \", m);\r\n }\r\n \/\/ Print the newline character after inner for loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
8 8 8 8 8 8 8 8 \r\n7 7 7 7 7 7 7 \r\n6 6 6 6 6 6 \r\n5 5 5 5 5 \r\n4 4 4 4 \r\n3 3 3 \r\n2 2 \r\n1 \r\n<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
# Give the number of rows of the Inverted Right Triangle as user input using int(input()) and store it in a variable.\r\ntriNumRows = int(input(\r\n 'Enter some random number of rows of the Inverted Right Triangle Pattern = '))\r\n# Loop from the given number of rows to 0 using For loop and take iterator value as m.\r\nfor m in range(triNumRows, -1, -1):\r\n # Loop till the iterator value of the first loop using another nested For loop.\r\n for n in range(m):\r\n # Print the First Loop iterator value that is m and space character.\r\n print(m, end=' ')\r\n # Print the newline character after inner for loop.\r\n print()\r\n<\/pre>\n
Enter some random number of rows of the Inverted Right Triangle Pattern = 7\r\n7 7 7 7 7 7 7 \r\n6 6 6 6 6 6 \r\n5 5 5 5 5 \r\n4 4 4 4 \r\n3 3 3 \r\n2 2 \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 of the Inverted Right\r\n \/\/ Triangle as user input using cin and store it in a\r\n \/\/ variable.\r\n int triNumRows;\r\n cout << \"Enter some random number of rows of the \"\r\n \"Inverted Right Triangle Pattern = \"\r\n << endl;\r\n cin >> triNumRows;\r\n \/\/ Loop from the given number of rows to 0 using For\r\n \/\/ loop and take iterator value as m.\r\n for (int m = triNumRows; m >= 0; m--) {\r\n\r\n \/\/ Loop till the iterator value of the first loop\r\n \/\/ using another nested For loop.\r\n for (int n = 0; n < m; n++) {\r\n \/\/ Print the First Loop iterator value that is m\r\n \/\/ and space character.\r\n cout << m << \" \";\r\n }\r\n \/\/ Print the newline character after inner for loop.\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
Enter some random number of rows of the Inverted Right Triangle Pattern = \r\n6\r\n6 6 6 6 6 6 \r\n5 5 5 5 5 \r\n4 4 4 4 \r\n3 3 3 \r\n2 2 \r\n1<\/pre>\n
#include <stdio.h>\r\n\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows of the Inverted Right\r\n \/\/ Triangle as user input using scanf and store it in a\r\n \/\/ variable.\r\n int triNumRows;\r\n scanf(\"%d\", &triNumRows);\r\n \/\/ Loop from the given number of rows to 0 using For\r\n \/\/ loop and take iterator value as m.\r\n for (int m = triNumRows; m >= 0; m--) {\r\n\r\n \/\/ Loop till the iterator value of the first loop\r\n \/\/ using another nested For loop.\r\n for (int n = 0; n < m; n++) {\r\n \/\/ Print the First Loop iterator value that is m\r\n \/\/ and space character.\r\n printf(\"%d \", m);\r\n }\r\n \/\/ Print the newline character after inner for loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
15\r\n15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \r\n14 14 14 14 14 14 14 14 14 14 14 14 14 14 \r\n13 13 13 13 13 13 13 13 13 13 13 13 13 \r\n12 12 12 12 12 12 12 12 12 12 12 12 \r\n11 11 11 11 11 11 11 11 11 11 11 \r\n10 10 10 10 10 10 10 10 10 10 \r\n9 9 9 9 9 9 9 9 9 \r\n8 8 8 8 8 8 8 8 \r\n7 7 7 7 7 7 7 \r\n6 6 6 6 6 6 \r\n5 5 5 5 5 \r\n4 4 4 4 \r\n3 3 3 \r\n2 2 \r\n1<\/pre>\n
\n