{"id":11223,"date":"2021-09-30T14:30:30","date_gmt":"2021-09-30T09:00:30","guid":{"rendered":"https:\/\/python-programs.com\/?p=11223"},"modified":"2021-11-22T18:34:32","modified_gmt":"2021-11-22T13:04:32","slug":"python-program-to-print-right-triangle-number-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-right-triangle-number-pattern\/","title":{"rendered":"Python Program to Print Right Triangle Number Pattern"},"content":{"rendered":"
Guys who are serious about learning the concepts of the java programming language should practice this list of programs in java<\/a> and get a good grip on it for better results in exams or interviews.<\/p>\n Given the number of rows(largest number) the task is to print the Right Triangle Number 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 Triangle Number 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 Guys who are serious about learning the concepts of the java programming language should practice this list of programs in java and get a good grip on it for better results in exams or interviews. Given the number of rows(largest number) the task is to print the Right Triangle Number pattern in C, C++, and …<\/p>\ngiven number of rows of the right triangle = 11<\/pre>\n
1 \r\n2 2 \r\n3 3 3 \r\n4 4 4 4 \r\n5 5 5 5 5 \r\n6 6 6 6 6 6 \r\n7 7 7 7 7 7 7 \r\n8 8 8 8 8 8 8 8 \r\n9 9 9 9 9 9 9 9 9 \r\n10 10 10 10 10 10 10 10 10 10 \r\n11 11 11 11 11 11 11 11 11 11 11<\/pre>\n
given number of rows of the right triangle = 9<\/pre>\n
1 \r\n2 2 \r\n3 3 3 \r\n4 4 4 4 \r\n5 5 5 5 5 \r\n6 6 6 6 6 6 \r\n7 7 7 7 7 7 7 \r\n8 8 8 8 8 8 8 8 \r\n9 9 9 9 9 9 9 9 9<\/pre>\n
Program to Print Right Triangle Number Pattern 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 right-angled triangle Number pattern\r\n# as static input and store it in a variable.\r\ntriangleNum = 11\r\n# Loop from 1 to the number of rows using For loop.\r\nfor m in range(1, triangleNum+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 iterator value of the nested loop with space in the inner For loop.\r\n # (This prints the same number parent loop number of times)\r\n print(m, end=' ')\r\n # Print the newline character after ending of inner For loop.\r\n print()\r\n<\/pre>\n
1 \r\n2 2 \r\n3 3 3 \r\n4 4 4 4 \r\n5 5 5 5 5 \r\n6 6 6 6 6 6 \r\n7 7 7 7 7 7 7 \r\n8 8 8 8 8 8 8 8 \r\n9 9 9 9 9 9 9 9 9 \r\n10 10 10 10 10 10 10 10 10 10 \r\n11 11 11 11 11 11 11 11 11 11 11<\/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 \/\/ Number pattern\r\n \/\/ as static input and store it in a variable.\r\n int triangleNum = 19;\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= triangleNum;\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 << m << \" \";\r\n }\r\n \/\/ Print the iterator value of the parent loop with\r\n \/\/ space in the inner For loop.\r\n \/*(This prints the same number parent loop number of\r\n times*\/\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
1 \r\n2 2 \r\n3 3 3 \r\n4 4 4 4 \r\n5 5 5 5 5 \r\n6 6 6 6 6 6 \r\n7 7 7 7 7 7 7 \r\n8 8 8 8 8 8 8 8 \r\n9 9 9 9 9 9 9 9 9 \r\n10 10 10 10 10 10 10 10 10 10 \r\n11 11 11 11 11 11 11 11 11 11 11 \r\n12 12 12 12 12 12 12 12 12 12 12 12 \r\n13 13 13 13 13 13 13 13 13 13 13 13 13 \r\n14 14 14 14 14 14 14 14 14 14 14 14 14 14 \r\n15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 \r\n16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 \r\n17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 \r\n18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 \r\n19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19<\/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 \/\/ Number pattern\r\n \/\/ as static input and store it in a 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 iterator value of the parent loop\r\n \/\/ with space in the inner For loop.\r\n \/\/(This prints the same number parent loop\r\n \/\/number of times)\r\n printf(\"%d \", m);\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
1 \r\n2 2 \r\n3 3 3 \r\n4 4 4 4 \r\n5 5 5 5 5 \r\n6 6 6 6 6 6 \r\n7 7 7 7 7 7 7 \r\n8 8 8 8 8 8 8 8 \r\n9 9 9 9 9 9 9 9 9<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
\n
# Give the number of rows of the right-angled triangle Number pattern as user input using int(input())\r\n# and store it in a variable.\r\ntriangleNum = int(\r\n input('Enter some random number of rows of the triangle Number pattern ='))\r\n# Loop from 1 to the number of rows using For loop.\r\nfor m in range(1, triangleNum+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 iterator value of the nested loop with space in the inner For loop.\r\n # (This prints the same number parent loop number of times)\r\n print(m, 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 triangle Number pattern =12\r\n1 \r\n2 2 \r\n3 3 3 \r\n4 4 4 4 \r\n5 5 5 5 5 \r\n6 6 6 6 6 6 \r\n7 7 7 7 7 7 7 \r\n8 8 8 8 8 8 8 8 \r\n9 9 9 9 9 9 9 9 9 \r\n10 10 10 10 10 10 10 10 10 10 \r\n11 11 11 11 11 11 11 11 11 11 11 \r\n12 12 12 12 12 12 12 12 12 12 12 12<\/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-angled triangle\r\n \/\/ Number pattern\r\n \/\/ as user input using cin and store it in a variable.\r\n int triangleNum;\r\n cout << \"Enter some random number of rows of the \"\r\n \"triangle Number pattern = \"\r\n << endl;\r\n cin >> triangleNum;\r\n \/\/ Loop from 1 to the number of rows using For loop.\r\n for (int m = 1; m <= triangleNum;\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 << m << \" \";\r\n }\r\n \/\/ Print the iterator value of the parent loop with\r\n \/\/ space in the inner For loop.\r\n \/*(This prints the same number parent loop number of\r\n times*\/\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
Enter some random number of rows of the triangle Number pattern = \r\n5\r\n1 \r\n2 2 \r\n3 3 3 \r\n4 4 4 4 \r\n5 5 5 5 5<\/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-angled triangle\r\n \/\/ Number pattern\r\n \/\/ as user input using scanf and store it in a variable.\r\n int trianglerows;\r\n scanf(\"%d\", &trianglerows);\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 iterator value of the parent loop\r\n \/\/ with space in the inner For loop.\r\n \/\/(This prints the same number parent loop\r\n \/\/ number of times)\r\n printf(\"%d \", m);\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
8\r\n1 \r\n2 2 \r\n3 3 3 \r\n4 4 4 4 \r\n5 5 5 5 5 \r\n6 6 6 6 6 6 \r\n7 7 7 7 7 7 7 \r\n8 8 8 8 8 8 8 8<\/pre>\n
\n