{"id":11351,"date":"2021-09-30T15:00:00","date_gmt":"2021-09-30T09:30:00","guid":{"rendered":"https:\/\/python-programs.com\/?p=11351"},"modified":"2021-11-22T18:34:30","modified_gmt":"2021-11-22T13:04:30","slug":"python-program-to-print-hollow-inverted-right-triangle","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-hollow-inverted-right-triangle\/","title":{"rendered":"Python Program to Print Hollow Inverted Right Triangle"},"content":{"rendered":"
Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output<\/a> & achieve your goal in improving java coding skills.<\/p>\n Given the number of rows of the Triangle, the task is to Print a Hollow Inverted Right Triangle Star Pattern in C, C++, and Python.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n <\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print a Hollow Inverted Right Triangle Star 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 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 Related Programs<\/strong>:<\/p>\n Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills. Given the number of rows of the Triangle, the task is to Print a Hollow Inverted …<\/p>\nGiven number of rows of the Hollow Inverted Right Triangle Pattern =7<\/pre>\n
*******\r\n* *\r\n* *\r\n* *\r\n* *\r\n* *\r\n*<\/pre>\n
Given number of rows of the Hollow Inverted Right Triangle Pattern =9\r\nGiven character to print ='^'<\/pre>\n
^^^^^^^^^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 ^\r\n^\u00a0 \u00a0 \u00a0 ^\r\n^\u00a0 \u00a0 ^\r\n^ ^\r\n^<\/pre>\n
Program to Print Hollow Inverted Right Triangle Star Pattern in C, C++, and Python<\/h2>\n
\n
Method #1: Using For Loop(Star Character)<\/h3>\n
\n
# Give the number of rows of the Hollow Inverted Right Triangle as static input and store it in a variable.\r\ntriNumRows = 7\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, 0, -1):\r\n # Loop from the iterator value of the first loop to 0 using another nested For loop.\r\n for n in range(m, 0, -1):\r\n # If\u00a0m\u00a0equals\u00a0zero,\u00a0rows,\u00a0n,\u00a0or\u00a0n\u00a0equals\u00a0one\u00a0value,\u00a0the\u00a0if\u00a0statement\u00a0prints\u00a0stars.\r\n if m == 1 or m == triNumRows or n == 1 or n == m:\r\n print('*', end='')\r\n else:\r\n print(' ', end='')\r\n # Print the newline character after inner for loop.\r\n print()\r\n<\/pre>\n
*******\r\n* *\r\n* *\r\n* *\r\n* *\r\n* *\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 = 7;\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 from the iterator value of the first loop to\r\n \/\/ 0 using another nested For loop.\r\n for (int n = m; n > 0; n--) {\r\n \/\/ If m equals zero, rows, n, or n equals one\r\n \/\/ value, the if statement prints stars.\r\n if (m == 1 || m == triNumRows || n == 1\r\n || n == m)\r\n cout << \"* \";\r\n else\r\n cout << \" \";\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
*******\r\n* *\r\n* *\r\n* *\r\n* *\r\n* *\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 = 7;\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 from the iterator value of the first loop to\r\n \/\/ 0 using another nested For loop.\r\n for (int n = m; n > 0; n--) {\r\n \/\/ If m equals zero, rows, n, or n equals one\r\n \/\/ value, the if statement prints stars.\r\n if (m == 1 || m == triNumRows || n == 1\r\n || n == m)\r\n printf(\"* \");\r\n else\r\n printf(\" \");\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
*******\r\n* *\r\n* *\r\n* *\r\n* *\r\n* *\r\n*<\/pre>\n
Method #2: Using For Loop(User Character)<\/h3>\n
\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# Give the Character as user input using input() and store it in another variable.\r\ngivencharacter = input('Enter some random character = ')\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, 0, -1):\r\n # Loop from the iterator value of the first loop to 0 using another nested For loop.\r\n for n in range(m, 0, -1):\r\n # If\u00a0m\u00a0equals\u00a0zero,\u00a0rows,\u00a0n,\u00a0or\u00a0n\u00a0equals\u00a0one\u00a0value,\u00a0the\u00a0if\u00a0statement\u00a0prints\u00a0stars.\r\n if m == 1 or m == triNumRows or n == 1 or n == m:\r\n print(givencharacter, end='')\r\n else:\r\n print(' ', 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 = 9\r\nEnter some random character = ^\r\n^^^^^^^^^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 ^\r\n^\u00a0 \u00a0 \u00a0 ^\r\n^\u00a0 \u00a0 ^\r\n^ ^\r\n^<\/pre>\n
\n
#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\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 char givencharacter;\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 \/\/ Give the Character as user input using cin and store\r\n \/\/ it in another variable.\r\n cout << \"Enter some random character = \" << endl;\r\n cin >> givencharacter;\r\n cout << endl;\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 from the iterator value of the first loop to\r\n \/\/ 0 using another nested For loop.\r\n for (int n = m; n > 0; n--) {\r\n \/\/ If m equals zero, rows, n, or n equals one\r\n \/\/ value, the if statement prints stars.\r\n if (m == 1 || m == triNumRows || n == 1\r\n || n == m)\r\n cout << givencharacter << \" \";\r\n else\r\n cout << \" \";\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 = 9\r\nEnter some random character = ^\r\n^^^^^^^^^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 ^\r\n^\u00a0 \u00a0 \u00a0 ^\r\n^\u00a0 \u00a0 ^\r\n^ ^\r\n^<\/pre>\n
\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 char givencharacter;\r\n \/\/ Give the Character as user input using scanf and\r\n \/\/ store it in another variable.\r\n\r\n scanf(\"%d\", &triNumRows);\r\n scanf(\"%c\", &givencharacter);\r\n printf(\"\\n\");\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 from the iterator value of the first loop to\r\n \/\/ 0 using another nested For loop.\r\n for (int n = m; n > 0; n--) {\r\n \/\/ If m equals zero, rows, n, or n equals one\r\n \/\/ value, the if statement prints stars.\r\n if (m == 1 || m == triNumRows || n == 1\r\n || n == m)\r\n printf(\"%c \", givencharacter);\r\n else\r\n printf(\" \");\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
9^\r\n^^^^^^^^^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0^\r\n^\u00a0 \u00a0 \u00a0 \u00a0 ^\r\n^\u00a0 \u00a0 \u00a0 ^\r\n^\u00a0 \u00a0 ^\r\n^ ^\r\n^<\/pre>\n
\n