{"id":11322,"date":"2021-09-30T14:30:45","date_gmt":"2021-09-30T09:00:45","guid":{"rendered":"https:\/\/python-programs.com\/?p=11322"},"modified":"2021-11-22T18:34:31","modified_gmt":"2021-11-22T13:04:31","slug":"python-program-to-print-inverted-right-triangle-star-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-inverted-right-triangle-star-pattern\/","title":{"rendered":"Python Program to Print Inverted Right Triangle Star Pattern"},"content":{"rendered":"
Explore complete java concepts from the Java programming examples<\/a> and get ready to become a good programmer and crack the java software developer interview with ease.<\/p>\n Given the number of rows of the Triangle, the task is to Print an 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 Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print an 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 Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease. Given the number of rows of the Triangle, the task is to Print an Inverted Right Triangle Star Pattern in C, C++, and Python. Examples: Example1: Input: Given number …<\/p>\nGiven number of rows of the Inverted Right Triangle Pattern =13<\/pre>\n
* * * * * * * * * * * * * \r\n* * * * * * * * * * * * \r\n* * * * * * * * * * * \r\n* * * * * * * * * * \r\n* * * * * * * * * \r\n* * * * * * * * \r\n* * * * * * * \r\n* * * * * * \r\n* * * * * \r\n* * * * \r\n* * * \r\n* * \r\n*<\/pre>\n
Given number of rows of the Inverted Right Triangle Pattern =9\r\nGiven character to print ='<'<\/pre>\n
< < < < < < < < < \r\n< < < < < < < < \r\n< < < < < < < \r\n< < < < < < \r\n< < < < < \r\n< < < < \r\n< < < \r\n< < \r\n<<\/pre>\n
Program to Print 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 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 star and space character in the inner for loop.\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* * * * * * * \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 = 5;\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 star and space character in the\r\n \/\/ inner for loop.\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*<\/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 = 13;\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 star and space character in the\r\n \/\/ inner for loop.\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* * * * * * * \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, -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 given character with the space\r\n print(givencharacter, 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\nEnter some random character = @\r\n@ @ @ @ @ @ @ \r\n@ @ @ @ @ @ \r\n@ @ @ @ @ \r\n@ @ @ @ \r\n@ @ @ \r\n@ @ \r\n@<\/pre>\n
\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 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\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 given character with the space\r\n cout << givencharacter << \" \";\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\n15\r\nEnter some random character = \r\n^\r\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ \r\n^ ^ ^ ^ \r\n^ ^ ^ \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 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 given character and space character\r\n \/\/ in the inner for loop.\r\n printf(\"%c \", givencharacter);\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< < < < < < < < \r\n< < < < < < < \r\n< < < < < < \r\n< < < < < \r\n< < < < \r\n< < < \r\n< < \r\n<<\/pre>\n
\n