{"id":11205,"date":"2021-09-30T14:30:21","date_gmt":"2021-09-30T09:00:21","guid":{"rendered":"https:\/\/python-programs.com\/?p=11205"},"modified":"2021-11-22T18:34:33","modified_gmt":"2021-11-22T13:04:33","slug":"python-program-to-print-right-angled-triangle-star-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-right-angled-triangle-star-pattern\/","title":{"rendered":"Python Program to Print Right Angled Triangle Star Pattern"},"content":{"rendered":"
Want to excel in java coding? Practice with these Java Programs examples with output<\/a> and write any kind of easy or difficult programs in the java language<\/p>\n Given the number of rows of the right-angled 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 the right-angled 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 Want to excel in java coding? Practice with these Java Programs examples with output and write any kind of easy or difficult programs in the java language Given the number of rows of the right-angled triangle star pattern in C, C++, and python. Examples: Example1: Input: given number of rows of the right-angled triangle star …<\/p>\ngiven number of rows of the right-angled triangle star pattern=19<\/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* * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * *<\/pre>\n
given number of rows of the right-angled triangle star pattern=11\r\ngiven character to print =^<\/pre>\n
^ \r\n^ ^ \r\n^ ^ ^ \r\n^ ^ ^ ^ \r\n^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \r\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^<\/pre>\n
Program to Print Right Angled 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-angled triangle star pattern\r\n# as static input and store it in a variable.\r\ntrianglerows = 19\r\n# Loop from 1 to the number of rows using For loop.\r\nfor m in range(1, trianglerows+1):\r\n # Loop from 1 to first loop iterator value using another Nested For loop.\r\n for n in range(1, m+1):\r\n # Print the star character with space in the inner For loop.\r\n print('*', end=' ')\r\n #Print\u00a0the\u00a0newline\u00a0character\u00a0after\u00a0ending\u00a0of\u00a0inner\u00a0For\u00a0loop.\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* * * * * * * * * * * * * \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 right-angled triangle\r\n \/\/ star pattern as static input and store it in a\r\n \/\/ variable.\r\n int trianglerows = 11;\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= trianglerows;\r\n m++) { \/\/ Loop from 1 to first loop iterator value\r\n \/\/ using another Nested For loop.\r\n for (int n = 1; n <= m; n++) {\r\n \/\/ Print the star character with space in the\r\n \/\/ inner For loop.\r\n cout << \"* \";\r\n }\r\n \/\/ Print the newline character after ending of inner\r\n \/\/ 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* * * * * * * \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-angled triangle\r\n \/\/ star pattern as static input and store it in a\r\n \/\/ variable.\r\n int trianglerows = 9;\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= trianglerows;\r\n m++) { \/\/ Loop from 1 to first loop iterator value\r\n \/\/ using another Nested For loop.\r\n for (int n = 1; n <= m; n++) {\r\n \/\/ Print the star character with space in the\r\n \/\/ inner For loop.\r\n printf(\"* \");\r\n }\r\n \/\/ Print the newline character after ending of inner\r\n \/\/ 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* * * * * * * * *<\/pre>\n
Method #2: Using For loop (User Character )<\/h3>\n
\n
\n
# Give the number of rows of the right-angled triangle as user input using int(input()) and store it in a variable.\r\ntrianglerows = 17\r\n# Give the Character as user input using input() and store it in another variable.\r\ngivencharacter = '{'\r\nfor m in range(1, trianglerows+1):\r\n # Loop from 1 to first loop iterator value using another Nested For loop.\r\n for n in range(1, m+1):\r\n # Print the star character with space in the inner For loop.\r\n print(givencharacter, end=' ')\r\n # Print the newline character after ending of inner For loop.\r\n print()\r\n<\/pre>\n
Enter some random number of rows of the right-angled triangle = 14\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| | | | | | | | | | | | | |<\/pre>\n
\n
#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n int trianglerows;\r\n char givencharacter;\r\n\r\n \/\/ Give the number of rows of the right-angled triangle\r\n \/\/ as user input using cin and store it in a variable.\r\n cout << \"Enter some random number of rows of the \"\r\n \"right-angled triangle = \"\r\n << endl;\r\n cin >> trianglerows;\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 1 to the number of rows using For loop.\r\n for (int m = 1; m <= trianglerows;\r\n m++) { \/\/ Loop from 1 to first loop iterator value\r\n \/\/ using another Nested For loop.\r\n for (int n = 1; n <= m; n++) {\r\n \/\/ Print the star character with space in the\r\n \/\/ inner For loop.\r\n cout << givencharacter << \" \";\r\n }\r\n \/\/ Print the newline character after ending of inner\r\n \/\/ For loop.\r\n cout << endl;\r\n }\r\n return 0;\r\n}<\/pre>\n
Enter some random number of rows of the right-angled triangle = \r\n7\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<\/pre>\n
\n
#include <stdio.h>\r\n\r\nint main()\r\n{\r\n\r\n int trianglerows;\r\n char givencharacter;\r\n \/\/ Give the number of rows of the right-angled triangle\r\n \/\/ as user input using cin and store it in a variable.\r\n scanf(\"%d\", &trianglerows);\r\n\r\n \/\/ Give the Character as user input using cin and store\r\n \/\/ it in another variable.\r\n scanf(\"%c\", &givencharacter);\r\n printf(\"\\n\");\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= trianglerows;\r\n m++) { \/\/ Loop from 1 to first loop iterator value\r\n \/\/ using another Nested For loop.\r\n for (int n = 1; n <= m; n++) {\r\n \/\/ Print the star character with space in the\r\n \/\/ inner For loop.\r\n printf(\"%c \", givencharacter);\r\n }\r\n \/\/ Print the newline character after ending of inner\r\n \/\/ For loop.\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
11^\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