{"id":11517,"date":"2021-09-30T14:30:11","date_gmt":"2021-09-30T09:00:11","guid":{"rendered":"https:\/\/python-programs.com\/?p=11517"},"modified":"2021-11-22T18:34:33","modified_gmt":"2021-11-22T13:04:33","slug":"python-program-to-print-exponentially-increasing-star-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-exponentially-increasing-star-pattern\/","title":{"rendered":"Python Program to Print Exponentially Increasing Star 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, the task is to print Exponentially Increasing 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 Exponentially Increasing 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 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, the task is to print Exponentially Increasing Star Pattern in C, C++, and Python Examples: …<\/p>\ngiven number of rows =5<\/pre>\n
* \r\n* * \r\n* * * * \r\n* * * * * * * * \r\n* * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *<\/pre>\n
given number of rows =4\r\ngiven character to print =@<\/pre>\n
@ \r\n@ @ \r\n@ @ @ @ \r\n@ @ @ @ @ @ @ @ \r\n@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @<\/pre>\n
Program to Print Exponentially Increasing 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 pattern as static input and store it in a variable.\r\nrowsnumb = 5\r\n# Loop till a given number of rows using For loop.\r\nfor m in range(rowsnumb+1):\r\n # Calculate the exponential value of the first loop iterator\r\n # value using 2**(iterator value of the first loop).\r\n expvalue = 2**m\r\n # Loop till the exponential value using another For loop(Nested For loop).\r\n for n in range(expvalue):\r\n # Print the star character in the inner for loop.\r\n print(\"*\", end=\" \")\r\n # Print the newline character after the end of the inner for loop.\r\n print()\r\n<\/pre>\n
* \r\n* * \r\n* * * * \r\n* * * * * * * * \r\n* * * * * * * * * * * * * * * * \r\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *<\/pre>\n
#include <iostream>\r\n#include <math.h>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n \/\/ Give the number of rows of the pattern as static\r\n \/\/ input and store it in a variable.\r\n int rowsnumb = 5;\r\n \/\/ Loop till a given number of rows using For loop.\r\n for (int m = 0; m <= rowsnumb; m++) {\r\n \/\/ Calculate the exponential value of the first loop\r\n \/\/ iterator value using 2**(iterator value of the\r\n \/\/ first loop).\r\n int expvalue = pow(2, m);\r\n \/\/ Loop till the exponential value using another For\r\n \/\/ loop(Nested For loop).\r\n for (int n = 1; n <= expvalue; n++) {\r\n \/\/ Print the star character in the inner for\r\n \/\/ loop.\r\n cout << \"* \";\r\n }\r\n \/\/ Print the newline character after the end 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 <math.h>\r\n#include <stdio.h>\r\nint main()\r\n{\r\n \/\/ Give the number of rows of the pattern as static\r\n \/\/ input and store it in a variable.\r\n int rowsnumb = 5;\r\n \/\/ Loop till a given number of rows using For loop.\r\n for (int m = 0; m <= rowsnumb; m++) {\r\n \/\/ Calculate the exponential value of the first loop\r\n \/\/ iterator value using 2**(iterator value of the\r\n \/\/ first loop).\r\n int expvalue = pow(2, m);\r\n \/\/ Loop till the exponential value using another For\r\n \/\/ loop(Nested For loop).\r\n for (int n = 1; n <= expvalue; n++) {\r\n \/\/ Print the star character in the inner for\r\n \/\/ loop.\r\n printf(\"* \");\r\n }\r\n \/\/ Print the newline character after the end of the\r\n \/\/ inner for loop.\r\n printf(\"\\n\");\r\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 using int(input()) and store it in a variable.\r\nrowsnumb = int(input('Enter some random number of rows = '))\r\n# Give the Character as user input using input() and store it in another variable.\r\nusercharact = input('Enter some random character to print = ')\r\nfor m in range(rowsnumb+1):\r\n # Calculate the exponential value of the first loop iterator\r\n # value using 2**(iterator value of the first loop).\r\n expvalue = 2**m\r\n # Loop till the exponential value using another For loop(Nested For loop).\r\n for n in range(expvalue):\r\n # Print the user character in the inner for loop.\r\n print(usercharact, end=\" \")\r\n # Print the newline character after the end of the inner for loop.\r\n print()\r\n<\/pre>\n
Enter some random number of rows = 4\r\nEnter some random character to print = @\r\n@ \r\n@ @ \r\n@ @ @ @ \r\n@ @ @ @ @ @ @ @ \r\n@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @<\/pre>\n
\n
#include <iostream>\r\n#include <math.h>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n \/\/ Give the number of rows of the pattern as user input\r\n \/\/ and store it in a variable.\r\n int rowsnumb;\r\n cin >> rowsnumb;\r\n \/\/ Give the character to print as user input and store\r\n \/\/ it in a variable.\r\n char usercharact;\r\n cin >> usercharact;\r\n cout<<endl;\r\n \/\/ Loop till a given number of rows using For loop.\r\n for (int m = 0; m <= rowsnumb; m++) {\r\n \/\/ Calculate the exponential value of the first loop\r\n \/\/ iterator value using 2**(iterator value of the\r\n \/\/ first loop).\r\n int expvalue = pow(2, m);\r\n \/\/ Loop till the exponential value using another For\r\n \/\/ loop(Nested For loop).\r\n for (int n = 1; n <= expvalue; n++) {\r\n \/\/ Print the user character in the inner for\r\n \/\/ loop.\r\n cout << usercharact << \" \";\r\n }\r\n \/\/ Print the newline character after the end 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 = 4\r\nEnter some random character to print = @\r\n@ \r\n@ @ \r\n@ @ @ @ \r\n@ @ @ @ @ @ @ @ \r\n@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @<\/pre>\n
\n
#include <math.h>\r\n#include <stdio.h>\r\nint main()\r\n{ \/\/ Give the number of rows of the pattern as user input\r\n \/\/ and store it in a variable.\r\n int rowsnumb;\r\n scanf(\"%d\", &rowsnumb);\r\n \/\/ Give the character to print as user input and store\r\n \/\/ it in a variable.\r\n char usercharact;\r\n scanf(\"%c\", &usercharact);\r\n \/\/ Loop till a given number of rows using For loop.\r\n for (int m = 0; m <= rowsnumb; m++) {\r\n \/\/ Calculate the exponential value of the first loop\r\n \/\/ iterator value using 2**(iterator value of the\r\n \/\/ first loop).\r\n int expvalue = pow(2, m);\r\n \/\/ Loop till the exponential value using another For\r\n \/\/ loop(Nested For loop).\r\n for (int n = 1; n <= expvalue; n++) {\r\n \/\/ Print the user character in the inner for\r\n \/\/ loop.\r\n printf(\"%c \", usercharact);\r\n }\r\n \/\/ Print the newline character after the end of the\r\n \/\/ inner for loop.\r\n printf(\"\\n\");\r\n }\r\n\r\n return 0;\r\n}<\/pre>\n
@ \r\n@ @ \r\n@ @ @ @ \r\n@ @ @ @ @ @ @ @ \r\n@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @<\/pre>\n
\n