Open In App

Webkul Interview Coding Round Pattern

Last Updated : 06 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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++




// 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


C




// 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


Java




// Java implementation
import java.util.*;
 
class GFG{
     
// Driver Code   
public static void main(String[] args)
{
    int n, i, j;
    Scanner s = new Scanner(System.in);
 
    n = s.nextInt();
       
    for(i = 0; i < (n / 2) + 2; i++)
    {
        for(j = 0; j < n - i; j++)
        {
            System.out.print(" ");
        }
        for(j = 0; j < 2 * i + 1; j++)
        {
            System.out.print("@"); 
        }
        System.out.println();
    }
       
    for(i = 0; i < n; i++)
    {
        for(j = 0; j < (n / 2) + 1; j++)
        {
            if (j >= n / 2 - i && j >= i - n / 2)
            {
                System.out.print("*");
            }
            else
            System.out.print(" ");
        }
        for(j = 0; j < n; j++)
        {
            if (i == n / 2)
                System.out.print("@");
            else
                System.out.print(" ");
        }
        for(j = 0; j < (n / 2) + 1; j++)
        {
            if (j >= n / 2 - i && j >= i - n / 2)
                System.out.print("*");
        }
        System.out.println();
    }
}
}
 
// This code is contributed by divyesh072019


Python3




# Python3 implementation
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()


C#




// C# implementation
using System;
class GFG {
  static void Main()
  {
       
    int n, i, j;
    string val;
    val = Console.ReadLine();
    n = Convert.ToInt32(val);
      
    for (i = 0; i < (n/2) + 2; i++)
    {
        for (j = 0; j < n - i; j++)
        {
            Console.Write(" ");
        }
        for (j = 0; j < 2 * i + 1; j++)
        {
            Console.Write("@");
        }
        Console.WriteLine();
    }
      
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < (n/2) + 1; j++)
        {
            if (j >= n / 2 - i && j >= i - n / 2)
            {
                Console.Write("*");
            }
            else
            Console.Write(" ");
        }
        for (j = 0; j < n; j++)
        {
            if (i == n / 2)
                Console.Write("@");
            else
                Console.Write(" ");
        }
        for (j = 0; j < (n / 2) + 1; j++)
        {
            if (j >= n / 2 - i && j >= i - n / 2)
                Console.Write("*");
        }
        Console.WriteLine();
    }
  }
}
 
// This code is contributed by divyeshrabadiya07


Javascript




// JavaScript implementation
const readline = require('readline-sync');
 
// Driver code
function main() {
    let n = parseInt(readline.question('Enter value for n: '));
 
    for (let i = 0; i < (n / 2) + 2; i++) {
        for (let j = 0; j < n - i; j++) {
            process.stdout.write(" ");
        }
        for (let j = 0; j < 2 * i + 1; j++) {
            process.stdout.write("@");
        }
        console.log();
    }
 
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < (n / 2) + 1; j++) {
            if (j >= n / 2 - i && j >= i - n / 2) {
                process.stdout.write("*");
            } else {
                process.stdout.write(" ");
            }
        }
        for (let j = 0; j < n; j++) {
            if (i === n / 2) {
                process.stdout.write("@");
            } else {
                process.stdout.write(" ");
            }
        }
        for (let j = 0; j < (n / 2) + 1; j++) {
            if (j >= n / 2 - i && j >= i - n / 2) {
                process.stdout.write("*");
            }
        }
        console.log();
    }
}
 
// Invoke the main function
main();


Input: 

5

Output: 

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

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads