{"id":10885,"date":"2021-09-30T15:00:05","date_gmt":"2021-09-30T09:30:05","guid":{"rendered":"https:\/\/python-programs.com\/?p=10885"},"modified":"2021-11-22T18:34:30","modified_gmt":"2021-11-22T13:04:30","slug":"python-program-to-print-rectangle-star-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-rectangle-star-pattern\/","title":{"rendered":"Python Program to Print Rectangle Star Pattern"},"content":{"rendered":"
Enhancing programming skills is very important no matter what language you have chosen. So, practice frequently with these simple java programs<\/a> examples and excel in coding the complex logic.<\/p>\n Given the length, breadth of the rectangle the task is to print the rectangle 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 rectangle 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 Give the length and breadth of the rectangle as user input using the int(input()) function and store them in two separate variables.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 2) C++ Implementation<\/strong><\/p>\n Give the length and breadth of the rectangle as user input using the cin and store them in two separate variables.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 3) C Implementation<\/strong><\/p>\n Give the length and breadth of the rectangle as user input using the scanf and store them in two separate variables.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Enhancing programming skills is very important no matter what language you have chosen. So, practice frequently with these simple java programs examples and excel in coding the complex logic. Given the length, breadth of the rectangle the task is to print the rectangle star pattern in C, C++, and Python. Examples: Example1: Input: given length …<\/p>\ngiven length of rectangle =8\r\ngiven breadth of rectangle =29<\/pre>\n
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * *<\/pre>\n
given length of rectangle =19\r\ngiven breadth of rectangle =5<\/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
Program to Print Rectangle Star Pattern in C, C++, and Python<\/h2>\n
\n
Method #1: Using For loop (Static Input)<\/h3>\n
\n
# Give the length and breadth as static input and store them in two variables.\r\nlengthnum = 8\r\nbreadthnum = 11\r\n# Loop till the length of the rectangle using For loop.\r\nfor m in range(lengthnum):\r\n # Loop till the breadth of the rectangle using another nested For loop.\r\n for n in range(breadthnum):\r\n # Print the * character inside the nested For loop.\r\n print('* ', end=' ')\r\n print()\r\n<\/pre>\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 length and breadth as static input and store\r\n \/\/ them in two variables.\r\n int lengthnum = 11;\r\n int breadthnum = 23;\r\n \/\/ Loop till the length of the rectangle using For loop.\r\n for (int m = 0; m < lengthnum; m++) {\r\n \/\/ Loop till the breadth of the rectangle using\r\n \/\/ another nested For loop.\r\n for (int n = 0; n < breadthnum;n++) { \/\/ Print the * character inside the\r\n \/\/ nested For loop.\r\n cout << \"* \";\r\n }\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 \/\/ Give the length and breadth as static input and store\r\n \/\/ them in two variables.\r\n int lengthnum = 9;\r\n int breadthnum = 29;\r\n \/\/ Loop till the length of the rectangle using For loop.\r\n for (int m = 0; m < lengthnum; m++) {\r\n \/\/ Loop till the breadth of the rectangle using\r\n \/\/ another nested For loop.\r\n for (int n = 0; n < breadthnum; n++) {\r\n \/\/ Print the * character inside the\r\n \/\/ nested For loop.\r\n printf(\"* \");\r\n }\r\n printf(\"\\n\");\r\n }\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 Input)<\/h3>\n
\n
# Give the length and breadth of the rectangle as user input using the int(input()) function\r\n# and store them in two separate variables.\r\nlengthnum = int(input('Enter some random length value of the rectangle = '))\r\n\r\nbreadthnum=int(input('Enter some random breadth value of the rectangle = '))\r\n# Loop till the length of the rectangle using For loop.\r\nfor m in range(lengthnum):\r\n # Loop till the breadth of the rectangle using another nested For loop.\r\n for n in range(breadthnum):\r\n # Print the * character inside the nested For loop.\r\n print('* ', end=' ')\r\n print()\r\n<\/pre>\n
Enter some random length value of the rectangle = 9\r\nEnter some random breadth value of the rectangle = 4\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 length and breadth of the rectangle as user\r\n \/\/ input using the cin\r\n \/\/ and store them in two separate variables.\r\n int lengthnum, breadthnum;\r\n cout << \"Enter some random length and breadth of \"\r\n \"rectangle separated by spaces\"\r\n << endl;\r\n cin >> lengthnum >> breadthnum;\r\n \/\/ Loop till the length of the rectangle using For loop.\r\n for (int m = 0; m < lengthnum; m++) {\r\n \/\/ Loop till the breadth of the rectangle using\r\n \/\/ another nested For loop.\r\n for (int n = 0; n < breadthnum;\r\n n++) { \/\/ Print the * character inside the\r\n \/\/ nested For loop.\r\n cout << \"* \";\r\n }\r\n cout << endl;\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
Enter some random length and breadth of rectangle separated by spaces\r\n4 16\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 \/\/ Give the length and breadth of the rectangle as\r\n \/\/ user input using the scanf\r\n \/\/ and store them in two separate variables.\r\n int lengthnum,breadthnum ;\r\n printf(\"Enter some random length and breadth of rectangle separated by spaces \\n\");\r\n scanf(\"%d%d\", &lengthnum, &breadthnum);\r\n \/\/ Loop till the length of the rectangle using For loop.\r\n for (int m = 0; m < lengthnum; m++) {\r\n \/\/ Loop till the breadth of the rectangle using\r\n \/\/ another nested For loop.\r\n for (int n = 0; n < breadthnum; n++) {\r\n \/\/ Print the * character inside the\r\n \/\/ nested For loop.\r\n printf(\"* \");\r\n }\r\n printf(\"\\n\");\r\n }\r\n}<\/pre>\n
Enter some random length and breadth of rectangle separated by spaces\r\n8 15\r\n* * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * *<\/pre>\n
\n