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
Python
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
Input:
5
Output:
@
@@@
@@@@@
@@@@@@@
* *
** **
***@@@@@***
** **
* *
Recommended Posts:
- Webkul Interview Experience | Pattern Question
- Cigital Interview Experience (Coding Test Round 1)
- Thoughtworks Interview Experience | coding round
- Goldman Sachs Interview Experience | Coding Round
- CommVault Systems Interview Experience | Coding Round On-Campus Placements
- CommVault Interview Experience | Coding round for SDE
- Google Interview Experience for Internship (Coding Round)
- TCS NQT Coding Questions & How Coding Task Evaluated in TCS NQT
- Microsoft Non-tech Coding round
- Samsung RnD Coding Round Questions
- Standard Chartered - On Campus Coding Round Experience - NIT Jalandhar
- Google Internship 2020 - Google Online Challenge(1st Coding Round)
- Samsung R&D; Bangalore Coding Round Experience - NIT Jalandhar
- Informatica Coding Round Question
- BrowserStack Interview Experience | Set 2 (Coding Questions)
- BrowserStack Interview Experience | Set 3 (Coding Questions)
- MakeMyTrip Interview Experience | Set 5 (Online Coding)
- BrowserStack Interview Experience | Set 7 (Online Coding Questions)
- MakeMyTrip Interview Experience | Set 6 (Online Coding)
- Fiberlink (maas360) Interview Experience | Set 5 (Online Coding Question)
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.


