Webkul Interview Coding Round Pattern


This is a mixed pattern which uses the different types in one and this pattern was asked to me when I was giving the 1st round of coding in Webkul Interview.

Examples:

Input : 3
Output : 
                            @
                           @@@
                          @@@@@
                          *   *
                         **@@@**
                          *   *

Input : 5
Output : 
                            @
                           @@@
                          @@@@@
                         @@@@@@@
                         *     *
                        **     **
                       ***@@@@@***
                        **     **
                         *     *

Below is the implementation of the above pattern:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ implementation
#include <bits/stdc++.h>
   
using namespace std;
  
// Driver code
int main() {
    int n, i, j;
    cin >> n ;
      
    for (i = 0; i < (n/2) + 2; i++){
        for (j = 0; j < n - i; j++){
            cout << " ";
        }
        for (j = 0; j < 2 * i + 1; j++){
            cout <<"@"
        }
        cout << "\n";
    }
      
    for (i = 0; i < n; i++){
        for (j = 0; j < (n/2) + 1; j++){
            if (j >= n / 2 - i && j >= i - n / 2){
                cout << "*" ;
            }
            else
            cout << " ";
        }
        for (j = 0; j < n; j++){
            if (i == n / 2)
                cout <<"@" ;
            else
                cout <<" ";
        }
        for (j = 0; j < (n / 2) + 1; j++){
            if (j >= n / 2 - i && j >= i - n / 2)
                cout <<"*";
        }
        cout <<"\n";
    }
    return 0;
}
  
// This code is contributed by shivanisinghss2110

chevron_right


C

filter_none

edit
close

play_arrow

link
brightness_4
code

// C implementation
#include <stdio.h>
  
// Driver code
int main() {
    int n, i, j;
    scanf("%d", &n);
      
    for (i = 0; i < (n/2) + 2; i++){
        for (j = 0; j < n - i; j++){
            printf(" ");
        }
        for (j = 0; j < 2 * i + 1; j++){
            printf("@");
        }
        printf("\n");
    }
      
    for (i = 0; i < n; i++){
        for (j = 0; j < (n/2) + 1; j++){
            if (j >= n / 2 - i && j >= i - n / 2){
                printf("*");
            }
            else
            printf(" ");
        }
        for (j = 0; j < n; j++){
            if (i == n / 2)
                printf("@");
            else
                printf(" ");
        }
        for (j = 0; j < (n / 2) + 1; j++){
            if (j >= n / 2 - i && j >= i - n / 2)
                printf("*");
        }
        printf("\n");
    }
    return 0;
}
  
// This code is contributed by shubhamsingh10

chevron_right


Python

filter_none

edit
close

play_arrow

link
brightness_4
code

n=int(input())
  
for i in range(n//2+2):
    for j in range(n-i):
        print(" ",end="")
    for j in range(2*i+1):
        print("@",end="")
    print()
  
for i in range(n):
    for j in range(n//2+1):
        if (j>=n//2-i and j>=i-n//2):
            print("*",end="")
        else:
            print(" ",end="")
    for j in range(n):
        if i==n//2:
            print("@",end="")
        else:
            print(" ",end="")
    for j in range(n//2+1):
        if (j>=n//2-i and j>=i-n//2):
            print("*",end="")
    print()

chevron_right



Input:

5

Output:



     @
    @@@
   @@@@@
  @@@@@@@
  *     *
 **     **
***@@@@@***
 **     **
  *     *


Write your Interview Experience or mail it to contribute@geeksforgeeks.org




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.