{"id":11335,"date":"2021-09-30T15:00:53","date_gmt":"2021-09-30T09:30:53","guid":{"rendered":"https:\/\/python-programs.com\/?p=11335"},"modified":"2021-11-22T18:34:26","modified_gmt":"2021-11-22T13:04:26","slug":"python-program-to-print-mirrored-right-triangle-star-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-mirrored-right-triangle-star-pattern\/","title":{"rendered":"Python Program to Print Mirrored Right Triangle Star Pattern"},"content":{"rendered":"
Are you a job seeker and trying to find simple java programs for Interview?<\/a> This would be the right choice for you, just tap on the link and start preparing the java programs covered to crack the interview.<\/p>\n Given the number of rows of the right triangle, the task is to print Mirrored 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 Mirrored 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 Are you a job seeker and trying to find simple java programs for Interview? This would be the right choice for you, just tap on the link and start preparing the java programs covered to crack the interview. Given the number of rows of the right triangle, the task is to print Mirrored Right Triangle …<\/p>\ngiven number of rows of the right triangle =6<\/pre>\n
* \r\n * * \r\n * * * \r\n * * * * \r\n * * * * * \r\n* * * * * *<\/pre>\n
given number of rows of the right triangle =\r\nGiven character to print ='$'<\/pre>\n
\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $ $ \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ $ $ \r\n\u00a0 \u00a0 \u00a0 $ $ $ $ \r\n\u00a0 \u00a0$ $ $ $ $ \r\n$ $ $ $ $ $<\/pre>\n
Program to Print Mirrored 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 right triangle pattern as static input and store it in a variable.\r\ntriNumRows = 6\r\n# Iterate from 1 to given rows using the First for loop.\r\nfor m in range(1, triNumRows+1):\r\n # Iterate from 1 to given rows using another for loop(Nested For loop)\r\n for n in range(1, triNumRows+1):\r\n # Check if the iterator value of the inner for loop is less than or equal to given rows - first iterator value using If statement.\r\n if(n <= triNumRows - m):\r\n # If the statement is true then print space.\r\n print(' ', end=' ')\r\n else:\r\n # Else print star character with space.\r\n print('*', end=' ')\r\n #Print\u00a0the\u00a0newline\u00a0character\u00a0after\u00a0the\u00a0exit\u00a0of\u00a0the\u00a0inner\u00a0for\u00a0loop.\r\n print()\r\n<\/pre>\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 right triangle pattern\r\n \/\/ as static input and store it in a variable.\r\n int triNumRows = 6;\r\n \/\/ Iterate from 1 to given rows using First for loop.\r\n for (int m = 1; m <= triNumRows; m++) {\r\n \/\/ Iterate from 1 to given rows using another for\r\n \/\/ loop(Nested For loop)\r\n for (int n = 1; n <= triNumRows; n++) {\r\n \/\/ Check if the iterator value of the inner\r\n \/\/ for loop is less\r\n \/\/ than\r\n \/\/ or equal to given rows\r\n \/\/ first iterator value using If statement.\r\n if (n <= triNumRows - m) {\r\n \/\/ If the statement is true then print\r\n \/\/ space.\r\n cout << \" \";\r\n }\r\n else {\r\n \/\/ Else print star character with space.\r\n cout << \"* \";\r\n }\r\n }\r\n \/\/ Print the newline character after the exit of the\r\n \/\/ 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* * * * * *<\/pre>\n
#include <stdio.h>\r\n\r\nint main()\r\n{\r\n\r\n \/\/ Give the number of rows of the right triangle pattern\r\n \/\/ as static input and store it in a variable.\r\n int triNumRows = 6;\r\n \/\/ Iterate from 1 to given rows using First for loop.\r\n for (int m = 1; m <= triNumRows; m++) {\r\n \/\/ Iterate from 1 to given rows using another for\r\n \/\/ loop(Nested For loop)\r\n for (int n = 1; n <= triNumRows; n++) {\r\n \/\/ Check if the iterator value of the inner\r\n \/\/ for loop is less\r\n \/\/ than\r\n \/\/ or equal to given rows\r\n \/\/ first iterator value using If statement.\r\n if (n <= triNumRows - m) {\r\n \/\/ If the statement is true then print\r\n \/\/ space.\r\n printf(\" \");\r\n }\r\n else {\r\n \/\/ Else print star character with space.\r\n printf(\"* \");\r\n }\r\n }\r\n \/\/ Print the newline character after the exit of the\r\n \/\/ 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* * * * * *<\/pre>\n
Method #2: Using For Loop(User Character)<\/h3>\n
\n
\n
# Give the number of rows of the 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 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# Iterate from 1 to given rows using First for loop.\r\nfor m in range(1, triNumRows+1):\r\n # Iterate from 1 to given rows using another for loop(Nested For loop)\r\n for n in range(1, triNumRows+1):\r\n # Check if the iterator value of the inner for loop is less than or equal to given rows - first iterator value using If statement.\r\n if(n <= triNumRows - m):\r\n # If the statement is true then print space.\r\n print(' ', end=' ')\r\n else:\r\n # Else print star character with space.\r\n print(givencharacter, end=' ')\r\n print()\r\n<\/pre>\n
Enter some random number of rows of the Right Triangle Pattern = 6\r\nEnter some random character = $\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $ $ \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ $ $ \r\n\u00a0 \u00a0 \u00a0 $ $ $ $ \r\n\u00a0 \u00a0$ $ $ $ $ \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 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 \/\/ Iterate from 1 to given rows using First for loop.\r\n for (int m = 1; m <= triNumRows; m++) {\r\n \/\/ Iterate from 1 to given rows using another for\r\n \/\/ loop(Nested For loop)\r\n for (int n = 1; n <= triNumRows; n++) {\r\n \/\/ Check if the iterator value of the inner\r\n \/\/ for loop is less\r\n \/\/ than\r\n \/\/ or equal to given rows\r\n \/\/ first iterator value using If statement.\r\n if (n <= triNumRows - m) {\r\n \/\/ If the statement is true then print\r\n \/\/ space.\r\n cout << \" \";\r\n }\r\n else {\r\n \/\/ Else print star character with space.\r\n cout <<givencharacter<<\" \";\r\n }\r\n }\r\n \/\/ Print the newline character after the exit of the\r\n \/\/ 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 Right Triangle Pattern = \r\n6\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 $ $ \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ $ $ \r\n\u00a0 \u00a0 \u00a0 $ $ $ $ \r\n\u00a0 \u00a0$ $ $ $ $ \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 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 scanf(\"%d\", &triNumRows);\r\n scanf(\"%c\", &givencharacter);\r\n printf(\"\\n\");\r\n \/\/ Iterate from 1 to given rows using First for loop.\r\n for (int m = 1; m <= triNumRows; m++) {\r\n \/\/ Iterate from 1 to given rows using another for\r\n \/\/ loop(Nested For loop)\r\n for (int n = 1; n <= triNumRows; n++) {\r\n \/\/ Check if the iterator value of the inner\r\n \/\/ for loop is less\r\n \/\/ than\r\n \/\/ or equal to given rows\r\n \/\/ first iterator value using If statement.\r\n if (n <= triNumRows - m) {\r\n \/\/ If the statement is true then print\r\n \/\/ space.\r\n printf(\" \");\r\n }\r\n else {\r\n \/\/ Else print star character with space.\r\n printf(\"%c \", givencharacter);\r\n }\r\n }\r\n \/\/ Print the newline character after the exit of the\r\n \/\/ inner for loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
6$\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $ $ \r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0$ $ $ \r\n\u00a0 \u00a0 \u00a0 $ $ $ $ \r\n\u00a0 \u00a0$ $ $ $ $ \r\n$ $ $ $ $ $<\/pre>\n
\n