{"id":12040,"date":"2021-09-30T15:00:39","date_gmt":"2021-09-30T09:30:39","guid":{"rendered":"https:\/\/python-programs.com\/?p=12040"},"modified":"2021-11-22T18:34:27","modified_gmt":"2021-11-22T13:04:27","slug":"python-program-to-print-pattern-to-display-letters-of-the-word","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-pattern-to-display-letters-of-the-word\/","title":{"rendered":"Python Program to Print Pattern to Display Letters of the Word"},"content":{"rendered":"
Our website provided core java programs examples with output<\/a> aid beginners and expert coders to test their knowledge gap and learn accordingly.<\/p>\n Given a word the task is to print the letters of the word 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 display letters of the word 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 word as user input using input() and store it in a variable.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 2) C++ Implementation<\/strong><\/p>\n Give the word as user input using cin and store it in a variable.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n 3) C Implementation<\/strong><\/p>\n Give the word as user input using scanf and store it in a variable.<\/p>\n Below is the implementation<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Our website provided core java programs examples with output aid beginners and expert coders to test their knowledge gap and learn accordingly. Given a word the task is to print the letters of the word in C, C++, and Python. Examples: Example1: Input: Given string =”BTechGeeks” Output: B BT BTe BTec BTech BTechG BTechGe BTechGee …<\/p>\nGiven string =\"BTechGeeks\"<\/pre>\n
B\r\nBT\r\nBTe\r\nBTec\r\nBTech\r\nBTechG\r\nBTechGe\r\nBTechGee\r\nBTechGeek\r\nBTechGeeks<\/pre>\n
Given string =\"Aplustopper\"<\/pre>\n
A\r\nAp\r\nApl\r\nAplu\r\nAplus\r\nAplust\r\nAplusto\r\nAplustop\r\nAplustopp\r\nAplustoppe\r\nAplustopper<\/pre>\n
Pattern to display letters of the word in C, C++, and Python.<\/h2>\n
\n
Method #1: Using For loop (Static Input)<\/h3>\n
\n
# Give the word as static input and store it in a variable.\r\ngivenword = 'BTechGeeks'\r\n# Take an empty string and store it in a variable say sampstrng.\r\nsampstrng = \"\"\r\n# Traverse the given word(string) using For loop.\r\nfor wordchar in givenword:\r\n # Concatenate the iterator character to the sampstrng\u00a0using string Concatenation.\r\n sampstrng = sampstrng+wordchar\r\n # Print the sampstrng.\r\n print(sampstrng)\r\n<\/pre>\n
B\r\nBT\r\nBTe\r\nBTec\r\nBTech\r\nBTechG\r\nBTechGe\r\nBTechGee\r\nBTechGeek\r\nBTechGeeks<\/pre>\n
#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n\r\n \/\/ Give the word as static input and store it in a\r\n \/\/ variable.\r\n string givenword = \"BTechGeeks\";\r\n \/\/ Take an empty string and store it in a variable say\r\n \/\/ sampstrng.\r\n string sampstrng = \"\";\r\n \/\/ Traverse the given word(string) using For loop.\r\n for (int wordchar = 0; wordchar < givenword.length();\r\n wordchar++) {\r\n \/\/ Concatenate the iterator character to the\r\n \/\/ sampstrng\u00a0using string Concatenation.\r\n\r\n sampstrng = sampstrng + givenword[wordchar];\r\n \/\/ Print the sampstrng.\r\n cout << sampstrng << endl;\r\n }\r\n return 0;\r\n}<\/pre>\n
B\r\nBT\r\nBTe\r\nBTec\r\nBTech\r\nBTechG\r\nBTechGe\r\nBTechGee\r\nBTechGeek\r\nBTechGeeks<\/pre>\n
#include <stdio.h>\r\n#include <string.h>\r\nint main()\r\n{\r\n\r\n \/\/ Give the word as static input and store it in a\r\n \/\/ variable.\r\n char givenword[100] = \"BTechGeeks\";\r\n \/\/ Take an empty string and store it in a variable say\r\n \/\/ sampstrng.\r\n char sampstrng[100] = \"\";\r\n \/\/ Traverse the given word(string) using For loop.\r\n for (int wordchar = 0; wordchar < strlen(givenword);\r\n wordchar++) {\r\n \/\/ Concatenate the iterator character to the\r\n \/\/ sampstrng\u00a0using string Concatenation.\r\n\r\n sampstrng[wordchar] = givenword[wordchar];\r\n \/\/ Print the sampstrng.\r\n printf(\"%s\", sampstrng);\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
B\r\nBT\r\nBTe\r\nBTec\r\nBTech\r\nBTechG\r\nBTechGe\r\nBTechGee\r\nBTechGeek\r\nBTechGeeks<\/pre>\n
Method #2: Using For loop (User Input)<\/h3>\n
\n
# Give the word as user input and store it in a variable.\r\ngivenword = input('Enter some random word = ')\r\n# Take an empty string and store it in a variable say sampstrng.\r\nsampstrng = \"\"\r\n# Traverse the given word(string) using For loop.\r\nfor wordchar in givenword:\r\n # Concatenate the iterator character to the sampstrng\u00a0using string Concatenation.\r\n sampstrng = sampstrng+wordchar\r\n # Print the sampstrng.\r\n print(sampstrng)\r\n<\/pre>\n
Enter some random word = Aplustopper\r\nA\r\nAp\r\nApl\r\nAplu\r\nAplus\r\nAplust\r\nAplusto\r\nAplustop\r\nAplustopp\r\nAplustoppe\r\nAplustopper<\/pre>\n
#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n\r\n \/\/ Give the word as user input using cin and store it in\r\n \/\/ a variable.\r\n string givenword;\r\n cin >> givenword;\r\n \/\/ Take an empty string and store it in a variable say\r\n \/\/ sampstrng.\r\n string sampstrng = \"\";\r\n \/\/ Traverse the given word(string) using For loop.\r\n for (int wordchar = 0; wordchar < givenword.length();\r\n wordchar++) {\r\n \/\/ Concatenate the iterator character to the\r\n \/\/ sampstrng\u00a0using string Concatenation.\r\n\r\n sampstrng = sampstrng + givenword[wordchar];\r\n \/\/ Print the sampstrng.\r\n cout << sampstrng << endl;\r\n }\r\n return 0;\r\n}<\/pre>\n
Aplustopper\r\nA\r\nAp\r\nApl\r\nAplu\r\nAplus\r\nAplust\r\nAplusto\r\nAplustop\r\nAplustopp\r\nAplustoppe\r\nAplustopper<\/pre>\n
#include <stdio.h>\r\n#include <string.h>\r\nint main()\r\n{\r\n\r\n \/\/ Give the word as user input using scanfand store it\r\n \/\/ in a variable.\r\n char givenword[100];\r\n scanf(\"%s\", givenword);\r\n \/\/ Take an empty string and store it in a variable say\r\n \/\/ sampstrng.\r\n char sampstrng[100] = \"\";\r\n \/\/ Traverse the given word(string) using For loop.\r\n for (int wordchar = 0; wordchar < strlen(givenword);\r\n wordchar++) {\r\n \/\/ Concatenate the iterator character to the\r\n \/\/ sampstrng\u00a0using string Concatenation.\r\n\r\n sampstrng[wordchar] = givenword[wordchar];\r\n \/\/ Print the sampstrng.\r\n printf(\"%s\", sampstrng);\r\n printf(\"\\n\");\r\n }\r\n return 0;\r\n}<\/pre>\n
Aplustopper\r\nA\r\nAp\r\nApl\r\nAplu\r\nAplus\r\nAplust\r\nAplusto\r\nAplustop\r\nAplustopp\r\nAplustoppe\r\nAplustopper<\/pre>\n
\n