इस ट्यूटोरियल में, हम दिए गए व्युत्क्रम डायमंड पैटर्न को प्रिंट करने के कार्यक्रम पर चर्चा करेंगे।
इसके लिए, हमें N का मान प्रदान किया जाएगा। हमारा काम 2N-1 की ऊंचाई के अनुसार हीरे के प्रतिलोम पैटर्न को प्रिंट करना है।
उदाहरण
#include<bits/stdc++.h>
using namespace std;
//printing the inverse diamond pattern
void printDiamond(int n){
cout<<endl;
int i, j = 0;
//loop for the upper half
for (i = 0; i < n; i++) {
//left triangle
for (j = i; j < n; j++)
cout<<"*";
//middle triangle
for (j = 0; j < 2 * i + 1; j++)
cout<<" ";
//right triangle
for (j = i; j < n; j++)
cout<<"*";
cout<<endl;
}
//loop for the lower half
for (i = 0; i < n - 1; i++) {
//left triangle
for (j = 0; j < i + 2; j++)
cout<<"*";
//middle triangle
for (j = 0; j < 2 * (n - 1 - i) - 1; j++)
cout<<" ";
//right triangle
for (j = 0; j < i + 2; j++)
cout<<"*";
cout<<endl;
}
cout<<endl;
}
int main(){
int n = 5;
printDiamond(n);
return 0;
} आउटपुट
***** ***** **** **** *** *** ** ** * * ** ** *** *** **** **** ***** *****