यह आलेख C++ प्रोग्रामिंग का उपयोग करते हुए एक दिलचस्प पैटर्न को प्रिंट करता है। यहाँ निम्नलिखित के रूप में एल्गोरिथ्म है
एल्गोरिदम
Step-1 Define the size which will be double automatically Step-2 Print the upper section using a loop Step-3 Print the lower section using a loop
उदाहरण
उपरोक्त एल्गोरिथम के आधार पर, निम्नलिखित c++ कोड को इस प्रकार तैयार किया गया है;
#include <iostream>
using namespace std;
int main(){
int n=3;
int i,j;
// This is upper half of pattern
for (i=1; i<=n; i++){
for (j=1; j<=(2*n); j++){
// Left part of pattern
if (i<j)
cout<<" ";
else
cout<<"*";
// Right part of pattern
if (i<=((2*n)-j))
cout<<" ";
else
cout<<"*";
}
cout<<endl;
}
// This is lower half of pattern
for (i=1; i<=n; i++){
for (j=1;j<=(2*n);j++){
// Left part of pattern
if (i>(n-j+1))
cout<<" ";
else
cout<<"*";
// Right part of pattern
if ((i+n)>j)
cout<<" ";
else
cout<<"*";
}
cout<<endl;
}
return 0;
} उपरोक्त कोड के संकलन के बाद, दिलचस्प पैटर्न मुद्रित किया जाएगा जैसा दिखता है।
आउटपुट
* * * * * * * * * * * * * * * * * * * * * * * *