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++
// 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
filter_none
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 |
chevron_right
filter_none
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 |
chevron_right
filter_none
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 () |
chevron_right
filter_none
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 |
chevron_right
filter_none
Input:
5
Output:
@ @@@ @@@@@ @@@@@@@ * * ** ** ***@@@@@*** ** ** * *