Skip to content
Related Articles

Related Articles

Improve Article

Program to print the Alphabets of a Given Word using * pattern

  • Difficulty Level : Expert
  • Last Updated : 15 Jun, 2021

Given a word str, the task is to print the alphabets of this word using * pattern.
Examples: 
 

Input: GFG
Output:
   ******
  *      
 *       
 *       
 *   ****
 *   *  *
  *  *  *
   ***  *

 *******
 **     
 **     
 ****** 
 **     
 **     
 **     
        

   ******
  *      
 *       
 *       
 *   ****
 *   *  *
  *  *  *
   ***  *

Approach: A simple implementation is to form the pattern for each letter A-Z and call them as functions.
Below is the implementation of the above approach: 
 

C++




// C++ Program to print the Alphabets
// of a Given Word using * pattern
#include <iostream>
using namespace std;
char ch;
 
// Function to print the letter A
void a(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int a = 0; a < 8; a++) {
            if (i == 0 && (a == 0 || a == 7))
                cout << " ";
            else if (a < 2 || a > 5) {
                cout << ch;
            }
            else if (i < 2 || (i > 3 && i < 5)) {
                cout << ch;
            }
 
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter B
void b(void)
{
    cout << endl;
    for (int i = 0; i < 9; i++) {
        cout << ch << ch;
 
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                cout << ch;
            else if (i == 1)
                cout << ch;
            else if (i < 4 && i > 0
                     && r > 3) {
                cout << ch;
            }
 
            else if (i == 4 && r < 5) {
                cout << ch;
            }
            else if (i > 4 && i < 7
                     && r > 3) {
                cout << ch;
            }
            else if (i == 7) {
                cout << ch;
            }
            else if (i == 8 && r < 5) {
                cout << ch;
            }
 
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter C
void c(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
 
        cout << " ";
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o <= 1))
                cout << " ";
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o > 1)))
                cout << " ";
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o > 1)))
                cout << " ";
            else if ((i == 3 || i == 4
                      || i == 5)
                     && (o > 0))
                cout << " ";
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o > 1)))
                cout << " ";
            else if (i == 7
                     && (o <= 1))
                cout << " ";
            else {
                cout << ch;
            }
        }
        cout << endl;
    }
}
 
// Function to print the letter D
void d(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        {
            cout << " "<< ch;
        }
 
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o >= 6 - i))
                cout << " ";
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o < 6)))
                cout << " ";
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o < 6)))
                cout << " ";
            else if ((i == 3 || i == 4
                      || i == 5)
                     && (o < 7))
                cout << " ";
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o < 6)))
                cout << " ";
            else if (i == 7
                     && (o >= 6 - i + 7))
                cout << " ";
            else {
                cout << ch;
            }
        }
        cout << endl;
    }
}
 
// Function to print the letter E
void e(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int j = 0; j < 7; j++) {
            if (i == 0) {
                cout << ch;
            }
            else if (i > 0 && i < 3
                     && j < 2) {
                cout << ch;
            }
            else if (i == 3 && j < 6) {
                cout << ch;
            }
            else if (i > 3 && i < 6
                     && j < 2) {
                cout << ch;
            }
            else if (i == 6) {
                cout << ch;
            }
 
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter F
void f(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int j = 0; j < 7; j++) {
            if (i == 0) {
                cout << ch;
            }
            else if (i > 0 && i < 3
                     && j < 2) {
                cout << ch;
            }
            else if (i == 3 && j < 6) {
                cout << ch;
            }
            else if (i > 3 && i < 7
                     && j < 2) {
                cout << ch;
            }
 
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter G
void g(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
 
        cout << " ";
        for (int o = 0; o < 8; o++) {
            if (i == 4 && o > 3
                || (o == 4 || o == 7)
                       && i > 4) {
                cout << ch;
            }
 
            else if (i == 0 && (o <= 1))
                cout << " ";
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o > 1)))
                cout << " ";
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o > 1)))
                cout << " ";
            else if ((i == 3 || i == 4
                      || i == 5)
                     && (o > 0))
                cout << " ";
            else if (i == 6
                     && (o == 0 || (o > 1)))
                cout << " ";
            else if (i == 7
                     && (o <= 1 || o == 5
                         || o == 6))
                cout << " ";
            else {
                cout << ch;
            }
        }
        cout << endl;
    }
}
 
// Function to print the letter H
void h(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int h = 0; h < 8; h++) {
            if (h < 2 || h > 5) {
                cout << ch;
            }
            else if (i > 2 && i < 5) {
                cout << ch;
            }
 
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter I
void i(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
 
        cout << " ";
 
        for (int t = 0; t < 8; t++) {
 
            if ((i < 1 || i > 6)
                && t < 8) {
                cout << ch;
            }
 
            else if (i > 0 && t < 3)
                cout << " ";
            else if (i > 0 && t > 2
                     && t < 5) {
                cout << ch;
            }
            else if (i > 0 && t > 4)
                cout << " ";
            else {
            }
        }
        cout << endl;
    }
}
 
// Function to print the letter J
void j(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
 
        for (int h = 0; h < 8; h++) {
            if (i < 1) {
                cout << ch;
            }
            else if (i == 5 && h < 1) {
                cout << ch;
            }
            else if (i < 7 && h > 5) {
                cout << ch;
            }
            else if (i == 7
                     && (h == 0 || h == 7))
                cout << " ";
            else if (i > 5) {
                cout << ch;
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter K
void k(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
 
        for (int k1 = 0; k1 < 7; k1++) {
            if (k1 < 2) {
                cout << ch;
            }
            else if ((k1 >= 5 - i)
                     && (k1 <= 6 - i)) {
                cout << ch;
            }
 
            else if (i >= 4) {
                if (k1 == i - 2 || k1 == i - 1) {
                    cout << ch;
                }
                else
                    cout << " ";
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter L
void l(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
 
        {
            cout << ch << ch;
        }
        if (i == 6) {
            {
                cout << ch << ch;
            }
            {
                cout << ch << ch;
            }
            cout << ch << ch;
        }
        if (i == 7) {
            {
                cout << ch << ch;
            }
            {
                cout << ch << ch;
            }
            cout << ch << ch;
        }
        cout << endl;
    }
}
 
// Function to print the letter M
void m(void)
{
    cout << endl;
 
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int j = 0; j < 8; j++) {
            if (j == 0 || j == 7) {
                cout << ch;
            }
            else if (i < 4
                     && (j == 7 - i || j == i)) {
                cout << ch;
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter N
void n(void)
{
    cout << endl;
 
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int n = 0; n < 8; n++) {
            if (n < 2 || n > 5) {
                cout << ch;
            }
            else if (i == n - 1
                     || i == n + 1 || i == n) {
                cout << ch;
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter O
void o(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o <= 1 || o >= 6 - i))
                cout << " ";
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o < 6 && o > 1)))
                cout << " ";
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o < 6 && o > 1)))
                cout << " ";
            else if ((i == 3 || i == 4 || i == 5)
                     && (o > 0 && o < 7))
                cout << " ";
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o < 6 && o > 1)))
                cout << " ";
            else if (i == 7
                     && (o <= 1 || o >= 6 - i + 7))
                cout << " ";
            else {
                cout << ch;
            }
        }
        cout << endl;
    }
}
 
// Function to print the letter P
void p(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        {
            cout << ch << ch;
        }
 
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                cout << ch;
            else if (i == 1)
                cout << ch;
            else if (i < 4 && i > 0 && r > 3) {
                cout << ch;
            }
 
            else if (i == 4 && r < 5) {
                cout << ch;
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter Q
void q(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int o = 0; o < 8; o++) {
            if (o == i)
                cout << ch;
 
            else if (i == 0
                     && (o <= 1 || o >= 6 - i))
                cout << " ";
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o < 6 && o > 1)))
                cout << " ";
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o < 6 && o > 1)))
                cout << " ";
            else if ((i == 3 || i == 4 || i == 5)
                     && (o > 0 && o < 7))
                cout << " ";
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o < 6 && o > 1)))
                cout << " ";
            else if (i == 7
                     && (o <= 1 || o >= 6 - i + 7))
                cout << " ";
            else {
                cout << ch;
            }
        }
        cout << endl;
    }
}
 
// Function to print the letter R
void r(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        {
            cout << ch << ch;
        }
 
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                cout << ch;
            else if (i == 1)
                cout << ch;
            else if (i < 4 && i > 0
                     && r > 3) {
                cout << ch;
            }
 
            else if (i >= 4) {
                if (i == 4
                    && (r == 3 || r == 4)) {
                    cout << ch;
                }
 
                else if (r == i - 2
                         || r == i - 3) {
                    cout << ch;
                }
                else
                    cout << " ";
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter S
void s(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int j = 0; j < 7; j++) {
            if (i == 0 && j > 0) {
                cout << ch;
            }
            else if (i > 0 && i < 3
                     && j < 2) {
                cout << ch;
            }
            else if (i == 3 && j > 0
                     && j < 6) {
                cout << ch;
            }
            else if (i > 3 && i < 6
                     && j > 4) {
                cout << ch;
            }
            else if (i == 6 && j < 6) {
                cout << ch;
            }
 
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter T
void t(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
 
        cout << " ";
        for (int t = 0; t < 8; t++) {
 
            if (i < 2 && t < 8) {
                cout << ch;
            }
 
            if (i > 1 && t < 3)
                cout << " ";
            if (i > 1 && t > 2
                && t < 5) {
                cout << ch;
            }
            if (i > 1 && t > 4)
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter U
void u(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
 
        for (int h = 0; h < 8; h++) {
            if (i < 7 && (h < 2 || h > 5)) {
                cout << ch;
            }
            else if (i == 7
                     && (h == 0 || h == 7))
                cout << " ";
            else if (i > 5) {
                cout << ch;
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter V
void v(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int v = 0; v < 8; v++)
            if ((v == 0 || v == 7)
                && i < 4) {
                cout << ch;
            }
            else if ((v == i - 4 || v == 11 - i)
                     && i >= 4) {
                cout << ch;
            }
            else
                cout << " ";
        cout << endl;
    }
}
 
// Function to print the letter W
void w(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int j = 0; j < 8; j++) {
            if (j == 0 || j == 7) {
                cout << ch;
            }
            else if (i > 3
                     && (j == 7 - i || j == i)) {
                cout << ch;
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter X
void x(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int m = 0; m < 8; m++) {
            if (i == m || m == 7 - i) {
                cout << ch;
            }
            else
                cout << " ";
        }
 
        cout << endl;
    }
}
 
// Function to print the letter Y
void y(void)
{
    cout << endl;
    for (int i = 0; i < 8; i++) {
        cout << " ";
 
        for (int y = 0; y < 8; y++) {
            if (i < 4) {
                if (y == i || y == i + 1
                    || y == 6 - i || y == 7 - i) {
                    cout << ch;
                }
                else
                    cout << " ";
            }
            else if (y == 3 || y == 4) {
                cout << ch;
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the letter Z
void z(void)
{
    cout << endl;
 
    for (int i = 0; i < 8; i++) {
        cout << " ";
        for (int j = 0; j < 8; j++) {
            if (i == 0 || i == 7) {
                cout << ch;
            }
            else if (j == 7 - i) {
                cout << ch;
            }
            else
                cout << " ";
        }
        cout << endl;
    }
}
 
// Function to print the required pattern
// by taking out each characters in it
void printPattern(char* str)
{
 
    int in = 0;
 
    while (str[in]) {
 
        char ch = str[in];
        if (ch < 95)
            ch = ch + 32;
        switch (ch) {
        case 'a':
            a();
            break;
        case 'b':
            b();
            break;
        case 'c':
            c();
            break;
        case 'd':
            d();
            break;
        case 'e':
            e();
            break;
        case 'f':
            f();
            break;
        case 'g':
            g();
            break;
        case 'h':
            h();
            break;
        case 'i':
            i();
            break;
        case 'j':
            j();
            break;
        case 'k':
            k();
            break;
        case 'l':
            l();
            break;
        case 'm':
            m();
            break;
        case 'n':
            n();
            break;
        case 'o':
            o();
            break;
        case 'p':
            p();
            break;
        case 'q':
            q();
            break;
        case 'r':
            r();
            break;
        case 's':
            s();
            break;
        case 't':
            t();
            break;
        case 'u':
            u();
            break;
        case 'v':
            v();
            break;
        case 'w':
            w();
            break;
        case 'x':
            x();
            break;
        case 'y':
            y();
            break;
        case 'z':
            z();
            break;
        default:
            break;
        }
        in++;
    }
}
 
// Driver code
int main()
{
    ch = '*';
    char *str = "GFG";
    printPattern(str);
 
    return 0;
}
 
// This code is contributed by shubhamsingh

C




// C Program to print the Alphabets
// of a Given Word using * pattern
 
#include <stdio.h>
#include <string.h>
 
char ch;
 
// Function to print the letter A
void a(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int a = 0; a < 8; a++) {
            if (i == 0 && (a == 0 || a == 7))
                printf(" ");
            else if (a < 2 || a > 5) {
                printf("%c", ch);
            }
            else if (i < 2 || (i > 3 && i < 5)) {
                printf("%c", ch);
            }
 
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter B
void b(void)
{
    printf("\n");
    for (int i = 0; i < 9; i++) {
        printf(" %c%c", ch, ch);
 
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                printf("%c", ch);
            else if (i == 1)
                printf("%c", ch);
            else if (i < 4 && i > 0
                     && r > 3) {
                printf("%c", ch);
            }
 
            else if (i == 4 && r < 5) {
                printf("%c", ch);
            }
            else if (i > 4 && i < 7
                     && r > 3) {
                printf("%c", ch);
            }
            else if (i == 7) {
                printf("%c", ch);
            }
            else if (i == 8 && r < 5) {
                printf("%c", ch);
            }
 
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter C
void c(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
 
        printf(" ");
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o <= 1))
                printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o > 1)))
                printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o > 1)))
                printf(" ");
            else if ((i == 3 || i == 4
                      || i == 5)
                     && (o > 0))
                printf(" ");
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o > 1)))
                printf(" ");
            else if (i == 7
                     && (o <= 1))
                printf(" ");
            else {
                printf("%c", ch);
            }
        }
        printf("\n");
    }
}
 
// Function to print the letter D
void d(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        {
            printf(" %c", ch);
        }
 
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o >= 6 - i))
                printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o < 6)))
                printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o < 6)))
                printf(" ");
            else if ((i == 3 || i == 4
                      || i == 5)
                     && (o < 7))
                printf(" ");
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o < 6)))
                printf(" ");
            else if (i == 7
                     && (o >= 6 - i + 7))
                printf(" ");
            else {
                printf("%c", ch);
            }
        }
        printf("\n");
    }
}
 
// Function to print the letter E
void e(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int j = 0; j < 7; j++) {
            if (i == 0) {
                printf("%c", ch);
            }
            else if (i > 0 && i < 3
                     && j < 2) {
                printf("%c", ch);
            }
            else if (i == 3 && j < 6) {
                printf("%c", ch);
            }
            else if (i > 3 && i < 6
                     && j < 2) {
                printf("%c", ch);
            }
            else if (i == 6) {
                printf("%c", ch);
            }
 
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter F
void f(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int j = 0; j < 7; j++) {
            if (i == 0) {
                printf("%c", ch);
            }
            else if (i > 0 && i < 3
                     && j < 2) {
                printf("%c", ch);
            }
            else if (i == 3 && j < 6) {
                printf("%c", ch);
            }
            else if (i > 3 && i < 7
                     && j < 2) {
                printf("%c", ch);
            }
 
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter G
void g(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
 
        printf(" ");
        for (int o = 0; o < 8; o++) {
            if (i == 4 && o > 3
                || (o == 4 || o == 7)
                       && i > 4) {
                printf("%c", ch);
            }
 
            else if (i == 0 && (o <= 1))
                printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o > 1)))
                printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o > 1)))
                printf(" ");
            else if ((i == 3 || i == 4
                      || i == 5)
                     && (o > 0))
                printf(" ");
            else if (i == 6
                     && (o == 0 || (o > 1)))
                printf(" ");
            else if (i == 7
                     && (o <= 1 || o == 5
                         || o == 6))
                printf(" ");
            else {
                printf("%c", ch);
            }
        }
        printf("\n");
    }
}
 
// Function to print the letter H
void h(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int h = 0; h < 8; h++) {
            if (h < 2 || h > 5) {
                printf("%c", ch);
            }
            else if (i > 2 && i < 5) {
                printf("%c", ch);
            }
 
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter I
void i(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
 
        printf(" ");
 
        for (int t = 0; t < 8; t++) {
 
            if ((i < 1 || i > 6)
                && t < 8) {
                printf("%c", ch);
            }
 
            else if (i > 0 && t < 3)
                printf(" ");
            else if (i > 0 && t > 2
                     && t < 5) {
                printf("%c", ch);
            }
            else if (i > 0 && t > 4)
                printf(" ");
            else {
            }
        }
        printf("\n");
    }
}
 
// Function to print the letter J
void j(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
 
        for (int h = 0; h < 8; h++) {
            if (i < 1) {
                printf("%c", ch);
            }
            else if (i == 5 && h < 1) {
                printf("%c", ch);
            }
            else if (i < 7 && h > 5) {
                printf("%c", ch);
            }
            else if (i == 7
                     && (h == 0 || h == 7))
                printf(" ");
            else if (i > 5) {
                printf("%c", ch);
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter K
void k(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
 
        for (int k1 = 0; k1 < 7; k1++) {
            if (k1 < 2) {
                printf("%c", ch);
            }
            else if ((k1 >= 5 - i)
                     && (k1 <= 6 - i)) {
                printf("%c", ch);
            }
 
            else if (i >= 4) {
                if (k1 == i - 2 || k1 == i - 1) {
                    printf("%c", ch);
                }
                else
                    printf(" ");
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter L
void l(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
 
        {
            printf("%c%c", ch, ch);
        }
        if (i == 6) {
            {
                printf("%c%c", ch, ch);
            }
            {
                printf("%c%c", ch, ch);
            }
            printf("%c%c", ch, ch);
        }
        if (i == 7) {
            {
                printf("%c%c", ch, ch);
            }
            {
                printf("%c%c", ch, ch);
            }
            printf("%c%c", ch, ch);
        }
        printf("\n");
    }
}
 
// Function to print the letter M
void m(void)
{
    printf("\n");
 
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int j = 0; j < 8; j++) {
            if (j == 0 || j == 7) {
                printf("%c", ch);
            }
            else if (i < 4
                     && (j == 7 - i || j == i)) {
                printf("%c", ch);
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter N
void n(void)
{
    printf("\n");
 
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int n = 0; n < 8; n++) {
            if (n < 2 || n > 5) {
                printf("%c", ch);
            }
            else if (i == n - 1
                     || i == n + 1 || i == n) {
                printf("%c", ch);
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter O
void o(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o <= 1 || o >= 6 - i))
                printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o < 6 && o > 1)))
                printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o < 6 && o > 1)))
                printf(" ");
            else if ((i == 3 || i == 4 || i == 5)
                     && (o > 0 && o < 7))
                printf(" ");
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o < 6 && o > 1)))
                printf(" ");
            else if (i == 7
                     && (o <= 1 || o >= 6 - i + 7))
                printf(" ");
            else {
                printf("%c", ch);
            }
        }
        printf("\n");
    }
}
 
// Function to print the letter P
void p(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        {
            printf("%c%c", ch, ch);
        }
 
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                printf("%c", ch);
            else if (i == 1)
                printf("%c", ch);
            else if (i < 4 && i > 0 && r > 3) {
                printf("%c", ch);
            }
 
            else if (i == 4 && r < 5) {
                printf("%c", ch);
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter Q
void q(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int o = 0; o < 8; o++) {
            if (o == i)
                printf("%c", ch);
 
            else if (i == 0
                     && (o <= 1 || o >= 6 - i))
                printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o < 6 && o > 1)))
                printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o < 6 && o > 1)))
                printf(" ");
            else if ((i == 3 || i == 4 || i == 5)
                     && (o > 0 && o < 7))
                printf(" ");
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o < 6 && o > 1)))
                printf(" ");
            else if (i == 7
                     && (o <= 1 || o >= 6 - i + 7))
                printf(" ");
            else {
                printf("%c", ch);
            }
        }
        printf("\n");
    }
}
 
// Function to print the letter R
void r(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        {
            printf("%c%c", ch, ch);
        }
 
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                printf("%c", ch);
            else if (i == 1)
                printf("%c", ch);
            else if (i < 4 && i > 0
                     && r > 3) {
                printf("%c", ch);
            }
 
            else if (i >= 4) {
                if (i == 4
                    && (r == 3 || r == 4)) {
                    printf("%c", ch);
                }
 
                else if (r == i - 2
                         || r == i - 3) {
                    printf("%c", ch);
                }
                else
                    printf(" ");
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter S
void s(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int j = 0; j < 7; j++) {
            if (i == 0 && j > 0) {
                printf("%c", ch);
            }
            else if (i > 0 && i < 3
                     && j < 2) {
                printf("%c", ch);
            }
            else if (i == 3 && j > 0
                     && j < 6) {
                printf("%c", ch);
            }
            else if (i > 3 && i < 6
                     && j > 4) {
                printf("%c", ch);
            }
            else if (i == 6 && j < 6) {
                printf("%c", ch);
            }
 
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter T
void t(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
 
        printf(" ");
        for (int t = 0; t < 8; t++) {
 
            if (i < 2 && t < 8) {
                printf("%c", ch);
            }
 
            if (i > 1 && t < 3)
                printf(" ");
            if (i > 1 && t > 2
                && t < 5) {
                printf("%c", ch);
            }
            if (i > 1 && t > 4)
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter U
void u(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
 
        for (int h = 0; h < 8; h++) {
            if (i < 7 && (h < 2 || h > 5)) {
                printf("%c", ch);
            }
            else if (i == 7
                     && (h == 0 || h == 7))
                printf(" ");
            else if (i > 5) {
                printf("%c", ch);
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter V
void v(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int v = 0; v < 8; v++)
            if ((v == 0 || v == 7)
                && i < 4) {
                printf("%c", ch);
            }
            else if ((v == i - 4 || v == 11 - i)
                     && i >= 4) {
                printf("%c", ch);
            }
            else
                printf(" ");
        printf("\n");
    }
}
 
// Function to print the letter W
void w(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int j = 0; j < 8; j++) {
            if (j == 0 || j == 7) {
                printf("%c", ch);
            }
            else if (i > 3
                     && (j == 7 - i || j == i)) {
                printf("%c", ch);
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter X
void x(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int m = 0; m < 8; m++) {
            if (i == m || m == 7 - i) {
                printf("%c", ch);
            }
            else
                printf(" ");
        }
 
        printf("\n");
    }
}
 
// Function to print the letter Y
void y(void)
{
    printf("\n");
    for (int i = 0; i < 8; i++) {
        printf(" ");
 
        for (int y = 0; y < 8; y++) {
            if (i < 4) {
                if (y == i || y == i + 1
                    || y == 6 - i || y == 7 - i) {
                    printf("%c", ch);
                }
                else
                    printf(" ");
            }
            else if (y == 3 || y == 4) {
                printf("%c", ch);
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the letter Z
void z(void)
{
    printf("\n");
 
    for (int i = 0; i < 8; i++) {
        printf(" ");
        for (int j = 0; j < 8; j++) {
            if (i == 0 || i == 7) {
                printf("%c", ch);
            }
            else if (j == 7 - i) {
                printf("%c", ch);
            }
            else
                printf(" ");
        }
        printf("\n");
    }
}
 
// Function to print the required pattern
// by taking out each characters in it
void printPattern(char* str)
{
 
    int in = 0;
 
    while (str[in]) {
 
        char ch = str[in];
        if (ch < 95)
            ch = ch + 32;
        switch (ch) {
        case 'a':
            a();
            break;
        case 'b':
            b();
            break;
        case 'c':
            c();
            break;
        case 'd':
            d();
            break;
        case 'e':
            e();
            break;
        case 'f':
            f();
            break;
        case 'g':
            g();
            break;
        case 'h':
            h();
            break;
        case 'i':
            i();
            break;
        case 'j':
            j();
            break;
        case 'k':
            k();
            break;
        case 'l':
            l();
            break;
        case 'm':
            m();
            break;
        case 'n':
            n();
            break;
        case 'o':
            o();
            break;
        case 'p':
            p();
            break;
        case 'q':
            q();
            break;
        case 'r':
            r();
            break;
        case 's':
            s();
            break;
        case 't':
            t();
            break;
        case 'u':
            u();
            break;
        case 'v':
            v();
            break;
        case 'w':
            w();
            break;
        case 'x':
            x();
            break;
        case 'y':
            y();
            break;
        case 'z':
            z();
            break;
        default:
            break;
        }
        in++;
    }
}
 
// Driver code
int main()
{
    ch = '*';
    char* str = "GFG";
    printPattern(str);
 
    return 0;
}

Java




// Java Program to print the Alphabets
// of a Given Word using * pattern
class GFG{
  
static char ch;
  
// Function to print the letter A
static void a()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int a = 0; a < 8; a++) {
            if (i == 0 && (a == 0 || a == 7))
                System.out.printf(" ");
            else if (a < 2 || a > 5) {
                System.out.printf("%c", ch);
            }
            else if (i < 2 || (i > 3 && i < 5)) {
                System.out.printf("%c", ch);
            }
  
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter B
static void b()
{
    System.out.printf("\n");
    for (int i = 0; i < 9; i++) {
        System.out.printf(" %c%c", ch, ch);
  
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                System.out.printf("%c", ch);
            else if (i == 1)
                System.out.printf("%c", ch);
            else if (i < 4 && i > 0
                     && r > 3) {
                System.out.printf("%c", ch);
            }
  
            else if (i == 4 && r < 5) {
                System.out.printf("%c", ch);
            }
            else if (i > 4 && i < 7
                     && r > 3) {
                System.out.printf("%c", ch);
            }
            else if (i == 7) {
                System.out.printf("%c", ch);
            }
            else if (i == 8 && r < 5) {
                System.out.printf("%c", ch);
            }
  
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter C
static void c()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
  
        System.out.printf(" ");
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o <= 1))
                System.out.printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o > 1)))
                System.out.printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o > 1)))
                System.out.printf(" ");
            else if ((i == 3 || i == 4
                      || i == 5)
                     && (o > 0))
                System.out.printf(" ");
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o > 1)))
                System.out.printf(" ");
            else if (i == 7
                     && (o <= 1))
                System.out.printf(" ");
            else {
                System.out.printf("%c", ch);
            }
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter D
static void d()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        {
            System.out.printf(" %c", ch);
        }
  
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o >= 6 - i))
                System.out.printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o < 6)))
                System.out.printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o < 6)))
                System.out.printf(" ");
            else if ((i == 3 || i == 4
                      || i == 5)
                     && (o < 7))
                System.out.printf(" ");
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o < 6)))
                System.out.printf(" ");
            else if (i == 7
                     && (o >= 6 - i + 7))
                System.out.printf(" ");
            else {
                System.out.printf("%c", ch);
            }
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter E
static void e()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int j = 0; j < 7; j++) {
            if (i == 0) {
                System.out.printf("%c", ch);
            }
            else if (i > 0 && i < 3
                     && j < 2) {
                System.out.printf("%c", ch);
            }
            else if (i == 3 && j < 6) {
                System.out.printf("%c", ch);
            }
            else if (i > 3 && i < 6
                     && j < 2) {
                System.out.printf("%c", ch);
            }
            else if (i == 6) {
                System.out.printf("%c", ch);
            }
  
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter F
static void f()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int j = 0; j < 7; j++) {
            if (i == 0) {
                System.out.printf("%c", ch);
            }
            else if (i > 0 && i < 3
                     && j < 2) {
                System.out.printf("%c", ch);
            }
            else if (i == 3 && j < 6) {
                System.out.printf("%c", ch);
            }
            else if (i > 3 && i < 7
                     && j < 2) {
                System.out.printf("%c", ch);
            }
  
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter G
static void g()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
  
        System.out.printf(" ");
        for (int o = 0; o < 8; o++) {
            if (i == 4 && o > 3
                || (o == 4 || o == 7)
                       && i > 4) {
                System.out.printf("%c", ch);
            }
  
            else if (i == 0 && (o <= 1))
                System.out.printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o > 1)))
                System.out.printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o > 1)))
                System.out.printf(" ");
            else if ((i == 3 || i == 4
                      || i == 5)
                     && (o > 0))
                System.out.printf(" ");
            else if (i == 6
                     && (o == 0 || (o > 1)))
                System.out.printf(" ");
            else if (i == 7
                     && (o <= 1 || o == 5
                         || o == 6))
                System.out.printf(" ");
            else {
                System.out.printf("%c", ch);
            }
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter H
static void h()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int h = 0; h < 8; h++) {
            if (h < 2 || h > 5) {
                System.out.printf("%c", ch);
            }
            else if (i > 2 && i < 5) {
                System.out.printf("%c", ch);
            }
  
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter I
static void i()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
  
        System.out.printf(" ");
  
        for (int t = 0; t < 8; t++) {
  
            if ((i < 1 || i > 6)
                && t < 8) {
                System.out.printf("%c", ch);
            }
  
            else if (i > 0 && t < 3)
                System.out.printf(" ");
            else if (i > 0 && t > 2
                     && t < 5) {
                System.out.printf("%c", ch);
            }
            else if (i > 0 && t > 4)
                System.out.printf(" ");
            else {
            }
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter J
static void j()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
  
        for (int h = 0; h < 8; h++) {
            if (i < 1) {
                System.out.printf("%c", ch);
            }
            else if (i == 5 && h < 1) {
                System.out.printf("%c", ch);
            }
            else if (i < 7 && h > 5) {
                System.out.printf("%c", ch);
            }
            else if (i == 7
                     && (h == 0 || h == 7))
                System.out.printf(" ");
            else if (i > 5) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter K
static void k()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
  
        for (int k1 = 0; k1 < 7; k1++) {
            if (k1 < 2) {
                System.out.printf("%c", ch);
            }
            else if ((k1 >= 5 - i)
                     && (k1 <= 6 - i)) {
                System.out.printf("%c", ch);
            }
  
            else if (i >= 4) {
                if (k1 == i - 2 || k1 == i - 1) {
                    System.out.printf("%c", ch);
                }
                else
                    System.out.printf(" ");
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter L
static void l()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
  
        {
            System.out.printf("%c%c", ch, ch);
        }
        if (i == 6) {
            {
                System.out.printf("%c%c", ch, ch);
            }
            {
                System.out.printf("%c%c", ch, ch);
            }
            System.out.printf("%c%c", ch, ch);
        }
        if (i == 7) {
            {
                System.out.printf("%c%c", ch, ch);
            }
            {
                System.out.printf("%c%c", ch, ch);
            }
            System.out.printf("%c%c", ch, ch);
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter M
static void m()
{
    System.out.printf("\n");
  
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int j = 0; j < 8; j++) {
            if (j == 0 || j == 7) {
                System.out.printf("%c", ch);
            }
            else if (i < 4
                     && (j == 7 - i || j == i)) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter N
static void n()
{
    System.out.printf("\n");
  
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int n = 0; n < 8; n++) {
            if (n < 2 || n > 5) {
                System.out.printf("%c", ch);
            }
            else if (i == n - 1
                     || i == n + 1 || i == n) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter O
static void o()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o <= 1 || o >= 6 - i))
                System.out.printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o < 6 && o > 1)))
                System.out.printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o < 6 && o > 1)))
                System.out.printf(" ");
            else if ((i == 3 || i == 4 || i == 5)
                     && (o > 0 && o < 7))
                System.out.printf(" ");
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o < 6 && o > 1)))
                System.out.printf(" ");
            else if (i == 7
                     && (o <= 1 || o >= 6 - i + 7))
                System.out.printf(" ");
            else {
                System.out.printf("%c", ch);
            }
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter P
static void p()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        {
            System.out.printf("%c%c", ch, ch);
        }
  
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                System.out.printf("%c", ch);
            else if (i == 1)
                System.out.printf("%c", ch);
            else if (i < 4 && i > 0 && r > 3) {
                System.out.printf("%c", ch);
            }
  
            else if (i == 4 && r < 5) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter Q
static void q()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int o = 0; o < 8; o++) {
            if (o == i)
                System.out.printf("%c", ch);
  
            else if (i == 0
                     && (o <= 1 || o >= 6 - i))
                System.out.printf(" ");
            else if (i == 1
                     && (o == 0 || o == 8 - i
                         || (o < 6 && o > 1)))
                System.out.printf(" ");
            else if (i == 2
                     && (o == 1 || o == 8 - i
                         || (o < 6 && o > 1)))
                System.out.printf(" ");
            else if ((i == 3 || i == 4 || i == 5)
                     && (o > 0 && o < 7))
                System.out.printf(" ");
            else if (i == 6
                     && (o == 0 || o == 8 + 5 - i
                         || (o < 6 && o > 1)))
                System.out.printf(" ");
            else if (i == 7
                     && (o <= 1 || o >= 6 - i + 7))
                System.out.printf(" ");
            else {
                System.out.printf("%c", ch);
            }
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter R
static void r()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        {
            System.out.printf("%c%c", ch, ch);
        }
  
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                System.out.printf("%c", ch);
            else if (i == 1)
                System.out.printf("%c", ch);
            else if (i < 4 && i > 0
                     && r > 3) {
                System.out.printf("%c", ch);
            }
  
            else if (i >= 4) {
                if (i == 4
                    && (r == 3 || r == 4)) {
                    System.out.printf("%c", ch);
                }
  
                else if (r == i - 2
                         || r == i - 3) {
                    System.out.printf("%c", ch);
                }
                else
                    System.out.printf(" ");
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter S
static void s()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int j = 0; j < 7; j++) {
            if (i == 0 && j > 0) {
                System.out.printf("%c", ch);
            }
            else if (i > 0 && i < 3
                     && j < 2) {
                System.out.printf("%c", ch);
            }
            else if (i == 3 && j > 0
                     && j < 6) {
                System.out.printf("%c", ch);
            }
            else if (i > 3 && i < 6
                     && j > 4) {
                System.out.printf("%c", ch);
            }
            else if (i == 6 && j < 6) {
                System.out.printf("%c", ch);
            }
  
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter T
static void t()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
  
        System.out.printf(" ");
        for (int t = 0; t < 8; t++) {
  
            if (i < 2 && t < 8) {
                System.out.printf("%c", ch);
            }
  
            if (i > 1 && t < 3)
                System.out.printf(" ");
            if (i > 1 && t > 2
                && t < 5) {
                System.out.printf("%c", ch);
            }
            if (i > 1 && t > 4)
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter U
static void u()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
  
        for (int h = 0; h < 8; h++) {
            if (i < 7 && (h < 2 || h > 5)) {
                System.out.printf("%c", ch);
            }
            else if (i == 7
                     && (h == 0 || h == 7))
                System.out.printf(" ");
            else if (i > 5) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter V
static void v()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int v = 0; v < 8; v++)
            if ((v == 0 || v == 7)
                && i < 4) {
                System.out.printf("%c", ch);
            }
            else if ((v == i - 4 || v == 11 - i)
                     && i >= 4) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        System.out.printf("\n");
    }
}
  
// Function to print the letter W
static void w()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int j = 0; j < 8; j++) {
            if (j == 0 || j == 7) {
                System.out.printf("%c", ch);
            }
            else if (i > 3
                     && (j == 7 - i || j == i)) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter X
static void x()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int m = 0; m < 8; m++) {
            if (i == m || m == 7 - i) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        }
  
        System.out.printf("\n");
    }
}
  
// Function to print the letter Y
static void y()
{
    System.out.printf("\n");
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
  
        for (int y = 0; y < 8; y++) {
            if (i < 4) {
                if (y == i || y == i + 1
                    || y == 6 - i || y == 7 - i) {
                    System.out.printf("%c", ch);
                }
                else
                    System.out.printf(" ");
            }
            else if (y == 3 || y == 4) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the letter Z
static void z()
{
    System.out.printf("\n");
  
    for (int i = 0; i < 8; i++) {
        System.out.printf(" ");
        for (int j = 0; j < 8; j++) {
            if (i == 0 || i == 7) {
                System.out.printf("%c", ch);
            }
            else if (j == 7 - i) {
                System.out.printf("%c", ch);
            }
            else
                System.out.printf(" ");
        }
        System.out.printf("\n");
    }
}
  
// Function to print the required pattern
// by taking out each characters in it
static void printPattern(char[] str)
{
  
    int in = 0;
  
    while (in<str.length) {
  
        char ch = str[in];
        if (ch < 95)
            ch = (char) (ch + 32);
        switch (ch) {
        case 'a':
            a();
            break;
        case 'b':
            b();
            break;
        case 'c':
            c();
            break;
        case 'd':
            d();
            break;
        case 'e':
            e();
            break;
        case 'f':
            f();
            break;
        case 'g':
            g();
            break;
        case 'h':
            h();
            break;
        case 'i':
            i();
            break;
        case 'j':
            j();
            break;
        case 'k':
            k();
            break;
        case 'l':
            l();
            break;
        case 'm':
            m();
            break;
        case 'n':
            n();
            break;
        case 'o':
            o();
            break;
        case 'p':
            p();
            break;
        case 'q':
            q();
            break;
        case 'r':
            r();
            break;
        case 's':
            s();
            break;
        case 't':
            t();
            break;
        case 'u':
            u();
            break;
        case 'v':
            v();
            break;
        case 'w':
            w();
            break;
        case 'x':
            x();
            break;
        case 'y':
            y();
            break;
        case 'z':
            z();
            break;
        default:
            break;
        }
        in++;
    }
}
  
// Driver code
public static void main(String[] args)
{
    ch = '*';
    char[] str = "GFG".toCharArray();
    printPattern(str);
  
}
}
 
// This code contributed by Rajput-Ji

C#




// C# Program to print the Alphabets
// of a Given Word using * pattern
using System;
 
class GFG{
 
static char ch;
 
// Function to print the letter A
static void a()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int a = 0; a < 8; a++) {
            if (i == 0 && (a == 0 || a == 7))
                Console.Write(" ");
            else if (a < 2 || a > 5) {
                Console.Write("{0}", ch);
            }
            else if (i < 2 || (i > 3 && i < 5)) {
                Console.Write("{0}", ch);
            }
 
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter B
static void b()
{
    Console.Write("\n");
    for (int i = 0; i < 9; i++) {
        Console.Write(" {0}{0}", ch, ch);
 
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                Console.Write("{0}", ch);
            else if (i == 1)
                Console.Write("{0}", ch);
            else if (i < 4 && i > 0
                    && r > 3) {
                Console.Write("{0}", ch);
            }
 
            else if (i == 4 && r < 5) {
                Console.Write("{0}", ch);
            }
            else if (i > 4 && i < 7
                    && r > 3) {
                Console.Write("{0}", ch);
            }
            else if (i == 7) {
                Console.Write("{0}", ch);
            }
            else if (i == 8 && r < 5) {
                Console.Write("{0}", ch);
            }
 
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter C
static void c()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
 
        Console.Write(" ");
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o <= 1))
                Console.Write(" ");
            else if (i == 1
                    && (o == 0 || o == 8 - i
                        || (o > 1)))
                Console.Write(" ");
            else if (i == 2
                    && (o == 1 || o == 8 - i
                        || (o > 1)))
                Console.Write(" ");
            else if ((i == 3 || i == 4
                    || i == 5)
                    && (o > 0))
                Console.Write(" ");
            else if (i == 6
                    && (o == 0 || o == 8 + 5 - i
                        || (o > 1)))
                Console.Write(" ");
            else if (i == 7
                    && (o <= 1))
                Console.Write(" ");
            else {
                Console.Write("{0}", ch);
            }
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter D
static void d()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        {
            Console.Write(" {0}", ch);
        }
 
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o >= 6 - i))
                Console.Write(" ");
            else if (i == 1
                    && (o == 0 || o == 8 - i
                        || (o < 6)))
                Console.Write(" ");
            else if (i == 2
                    && (o == 1 || o == 8 - i
                        || (o < 6)))
                Console.Write(" ");
            else if ((i == 3 || i == 4
                    || i == 5)
                    && (o < 7))
                Console.Write(" ");
            else if (i == 6
                    && (o == 0 || o == 8 + 5 - i
                        || (o < 6)))
                Console.Write(" ");
            else if (i == 7
                    && (o >= 6 - i + 7))
                Console.Write(" ");
            else {
                Console.Write("{0}", ch);
            }
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter E
static void e()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int j = 0; j < 7; j++) {
            if (i == 0) {
                Console.Write("{0}", ch);
            }
            else if (i > 0 && i < 3
                    && j < 2) {
                Console.Write("{0}", ch);
            }
            else if (i == 3 && j < 6) {
                Console.Write("{0}", ch);
            }
            else if (i > 3 && i < 6
                    && j < 2) {
                Console.Write("{0}", ch);
            }
            else if (i == 6) {
                Console.Write("{0}", ch);
            }
 
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter F
static void f()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int j = 0; j < 7; j++) {
            if (i == 0) {
                Console.Write("{0}", ch);
            }
            else if (i > 0 && i < 3
                    && j < 2) {
                Console.Write("{0}", ch);
            }
            else if (i == 3 && j < 6) {
                Console.Write("{0}", ch);
            }
            else if (i > 3 && i < 7
                    && j < 2) {
                Console.Write("{0}", ch);
            }
 
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter G
static void g()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
 
        Console.Write(" ");
        for (int o = 0; o < 8; o++) {
            if (i == 4 && o > 3
                || (o == 4 || o == 7)
                    && i > 4) {
                Console.Write("{0}", ch);
            }
 
            else if (i == 0 && (o <= 1))
                Console.Write(" ");
            else if (i == 1
                    && (o == 0 || o == 8 - i
                        || (o > 1)))
                Console.Write(" ");
            else if (i == 2
                    && (o == 1 || o == 8 - i
                        || (o > 1)))
                Console.Write(" ");
            else if ((i == 3 || i == 4
                    || i == 5)
                    && (o > 0))
                Console.Write(" ");
            else if (i == 6
                    && (o == 0 || (o > 1)))
                Console.Write(" ");
            else if (i == 7
                    && (o <= 1 || o == 5
                        || o == 6))
                Console.Write(" ");
            else {
                Console.Write("{0}", ch);
            }
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter H
static void h()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int h = 0; h < 8; h++) {
            if (h < 2 || h > 5) {
                Console.Write("{0}", ch);
            }
            else if (i > 2 && i < 5) {
                Console.Write("{0}", ch);
            }
 
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter I
static void i()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
 
        Console.Write(" ");
 
        for (int t = 0; t < 8; t++) {
 
            if ((i < 1 || i > 6)
                && t < 8) {
                Console.Write("{0}", ch);
            }
 
            else if (i > 0 && t < 3)
                Console.Write(" ");
            else if (i > 0 && t > 2
                    && t < 5) {
                Console.Write("{0}", ch);
            }
            else if (i > 0 && t > 4)
                Console.Write(" ");
            else {
            }
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter J
static void j()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
 
        for (int h = 0; h < 8; h++) {
            if (i < 1) {
                Console.Write("{0}", ch);
            }
            else if (i == 5 && h < 1) {
                Console.Write("{0}", ch);
            }
            else if (i < 7 && h > 5) {
                Console.Write("{0}", ch);
            }
            else if (i == 7
                    && (h == 0 || h == 7))
                Console.Write(" ");
            else if (i > 5) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter K
static void k()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
 
        for (int k1 = 0; k1 < 7; k1++) {
            if (k1 < 2) {
                Console.Write("{0}", ch);
            }
            else if ((k1 >= 5 - i)
                    && (k1 <= 6 - i)) {
                Console.Write("{0}", ch);
            }
 
            else if (i >= 4) {
                if (k1 == i - 2 || k1 == i - 1) {
                    Console.Write("{0}", ch);
                }
                else
                    Console.Write(" ");
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter L
static void l()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
 
        {
            Console.Write("{0}{0}", ch, ch);
        }
        if (i == 6) {
            {
                Console.Write("{0}{0}", ch, ch);
            }
            {
                Console.Write("{0}{0}", ch, ch);
            }
            Console.Write("{0}{0}", ch, ch);
        }
        if (i == 7) {
            {
                Console.Write("{0}{0}", ch, ch);
            }
            {
                Console.Write("{0}{0}", ch, ch);
            }
            Console.Write("{0}{0}", ch, ch);
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter M
static void m()
{
    Console.Write("\n");
 
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int j = 0; j < 8; j++) {
            if (j == 0 || j == 7) {
                Console.Write("{0}", ch);
            }
            else if (i < 4
                    && (j == 7 - i || j == i)) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter N
static void n()
{
    Console.Write("\n");
 
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int n = 0; n < 8; n++) {
            if (n < 2 || n > 5) {
                Console.Write("{0}", ch);
            }
            else if (i == n - 1
                    || i == n + 1 || i == n) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter O
static void o()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int o = 0; o < 8; o++) {
            if (i == 0 && (o <= 1 || o >= 6 - i))
                Console.Write(" ");
            else if (i == 1
                    && (o == 0 || o == 8 - i
                        || (o < 6 && o > 1)))
                Console.Write(" ");
            else if (i == 2
                    && (o == 1 || o == 8 - i
                        || (o < 6 && o > 1)))
                Console.Write(" ");
            else if ((i == 3 || i == 4 || i == 5)
                    && (o > 0 && o < 7))
                Console.Write(" ");
            else if (i == 6
                    && (o == 0 || o == 8 + 5 - i
                        || (o < 6 && o > 1)))
                Console.Write(" ");
            else if (i == 7
                    && (o <= 1 || o >= 6 - i + 7))
                Console.Write(" ");
            else {
                Console.Write("{0}", ch);
            }
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter P
static void p()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        {
            Console.Write("{0}{0}", ch, ch);
        }
 
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                Console.Write("{0}", ch);
            else if (i == 1)
                Console.Write("{0}", ch);
            else if (i < 4 && i > 0 && r > 3) {
                Console.Write("{0}", ch);
            }
 
            else if (i == 4 && r < 5) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter Q
static void q()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int o = 0; o < 8; o++) {
            if (o == i)
                Console.Write("{0}", ch);
 
            else if (i == 0
                    && (o <= 1 || o >= 6 - i))
                Console.Write(" ");
            else if (i == 1
                    && (o == 0 || o == 8 - i
                        || (o < 6 && o > 1)))
                Console.Write(" ");
            else if (i == 2
                    && (o == 1 || o == 8 - i
                        || (o < 6 && o > 1)))
                Console.Write(" ");
            else if ((i == 3 || i == 4 || i == 5)
                    && (o > 0 && o < 7))
                Console.Write(" ");
            else if (i == 6
                    && (o == 0 || o == 8 + 5 - i
                        || (o < 6 && o > 1)))
                Console.Write(" ");
            else if (i == 7
                    && (o <= 1 || o >= 6 - i + 7))
                Console.Write(" ");
            else {
                Console.Write("{0}", ch);
            }
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter R
static void r()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        {
            Console.Write("{0}{0}", ch, ch);
        }
 
        for (int r = 0; r < 6; r++) {
            if (i == 0 && r < 5)
                Console.Write("{0}", ch);
            else if (i == 1)
                Console.Write("{0}", ch);
            else if (i < 4 && i > 0
                    && r > 3) {
                Console.Write("{0}", ch);
            }
 
            else if (i >= 4) {
                if (i == 4
                    && (r == 3 || r == 4)) {
                    Console.Write("{0}", ch);
                }
 
                else if (r == i - 2
                        || r == i - 3) {
                    Console.Write("{0}", ch);
                }
                else
                    Console.Write(" ");
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter S
static void s()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int j = 0; j < 7; j++) {
            if (i == 0 && j > 0) {
                Console.Write("{0}", ch);
            }
            else if (i > 0 && i < 3
                    && j < 2) {
                Console.Write("{0}", ch);
            }
            else if (i == 3 && j > 0
                    && j < 6) {
                Console.Write("{0}", ch);
            }
            else if (i > 3 && i < 6
                    && j > 4) {
                Console.Write("{0}", ch);
            }
            else if (i == 6 && j < 6) {
                Console.Write("{0}", ch);
            }
 
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter T
static void t()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
 
        Console.Write(" ");
        for (int t = 0; t < 8; t++) {
 
            if (i < 2 && t < 8) {
                Console.Write("{0}", ch);
            }
 
            if (i > 1 && t < 3)
                Console.Write(" ");
            if (i > 1 && t > 2
                && t < 5) {
                Console.Write("{0}", ch);
            }
            if (i > 1 && t > 4)
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter U
static void u()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
 
        for (int h = 0; h < 8; h++) {
            if (i < 7 && (h < 2 || h > 5)) {
                Console.Write("{0}", ch);
            }
            else if (i == 7
                    && (h == 0 || h == 7))
                Console.Write(" ");
            else if (i > 5) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter V
static void v()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int v = 0; v < 8; v++)
            if ((v == 0 || v == 7)
                && i < 4) {
                Console.Write("{0}", ch);
            }
            else if ((v == i - 4 || v == 11 - i)
                    && i >= 4) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        Console.Write("\n");
    }
}
 
// Function to print the letter W
static void w()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int j = 0; j < 8; j++) {
            if (j == 0 || j == 7) {
                Console.Write("{0}", ch);
            }
            else if (i > 3
                    && (j == 7 - i || j == i)) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter X
static void x()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int m = 0; m < 8; m++) {
            if (i == m || m == 7 - i) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        }
 
        Console.Write("\n");
    }
}
 
// Function to print the letter Y
static void y()
{
    Console.Write("\n");
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
 
        for (int y = 0; y < 8; y++) {
            if (i < 4) {
                if (y == i || y == i + 1
                    || y == 6 - i || y == 7 - i) {
                    Console.Write("{0}", ch);
                }
                else
                    Console.Write(" ");
            }
            else if (y == 3 || y == 4) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the letter Z
static void z()
{
    Console.Write("\n");
 
    for (int i = 0; i < 8; i++) {
        Console.Write(" ");
        for (int j = 0; j < 8; j++) {
            if (i == 0 || i == 7) {
                Console.Write("{0}", ch);
            }
            else if (j == 7 - i) {
                Console.Write("{0}", ch);
            }
            else
                Console.Write(" ");
        }
        Console.Write("\n");
    }
}
 
// Function to print the required pattern
// by taking out each characters in it
static void printPattern(char[] str)
{
 
    int iN = 0;
 
    while (iN<str.Length) {
 
        char ch = str[iN];
        if (ch < 95)
            ch = (char) (ch + 32);
        switch (ch) {
        case 'a':
            a();
            break;
        case 'b':
            b();
            break;
        case 'c':
            c();
            break;
        case 'd':
            d();
            break;
        case 'e':
            e();
            break;
        case 'f':
            f();
            break;
        case 'g':
            g();
            break;
        case 'h':
            h();
            break;
        case 'i':
            i();
            break;
        case 'j':
            j();
            break;
        case 'k':
            k();
            break;
        case 'l':
            l();
            break;
        case 'm':
            m();
            break;
        case 'n':
            n();
            break;
        case 'o':
            o();
            break;
        case 'p':
            p();
            break;
        case 'q':
            q();
            break;
        case 'r':
            r();
            break;
        case 's':
            s();
            break;
        case 't':
            t();
            break;
        case 'u':
            u();
            break;
        case 'v':
            v();
            break;
        case 'w':
            w();
            break;
        case 'x':
            x();
            break;
        case 'y':
            y();
            break;
        case 'z':
            z();
            break;
        default:
            break;
        }
        iN++;
    }
}
 
// Driver code
public static void Main(String[] args)
{
    ch = '*';
    char[] str = "GFG".ToCharArray();
    printPattern(str);
 
}
}
// This code is contributed by 29AjayKumar
Output: 
   ******
  *      
 *       
 *       
 *   ****
 *   *  *
  *  *  *
   ***  *

 *******
 **     
 **     
 ****** 
 **     
 **     
 **     
        

   ******
  *      
 *       
 *       
 *   ****
 *   *  *
  *  *  *
   ***  *

 

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for the language and STL. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.



My Personal Notes arrow_drop_up
Recommended Articles
Page :