এই টিউটোরিয়ালে, আমরা প্রদত্ত কাইট প্যাটার্ন প্রিন্ট করার জন্য একটি প্রোগ্রাম নিয়ে আলোচনা করব।
এর জন্য, আমরা N=5 হিসাবে ইনপুট নিব। আমাদের কাজ হল প্রদত্ত কাইটস্ট্রাকচারটিকে 2N+1 =5 এর সামগ্রিক উচ্চতা সহ প্রিন্ট করা। এতে উপরের ডায়মন্ড স্ট্রাকচারের জন্য 9টি লাইন এবং নিচের অসম্পূর্ণ ডায়মন্ড স্ট্রাকচারের জন্য 2টি লাইন রয়েছে।
উদাহরণ
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
int main(){
int i, j, k, sp, space = 4;
char prt = '$';
//printing the upper half of the first diamond
for (i = 1; i <= 5; i++){
//printing the spaces in the front
for (sp = space; sp >= 1; sp--){
cout << " ";
}
//printing $ character
for (j = 1; j <= i; j++){
cout << prt;
}
for (k = 1; k <= (i - 1); k++){
if (i == 1){
continue;
}
cout << prt;
}
cout << "\n";
space--;
}
space = 1;
//printing the lower half of the first diamond
for (i = 4; i >= 1; i--){
for (sp = space; sp >= 1; sp--) {
cout << " ";
}
for (j = 1; j <= i; j++){
cout << prt;
}
for (k = 1; k <= (i - 1); k++){
cout << prt;
}
space++;
cout << "\n";
}
space = 3;
//printing the second incomplete diamond
for (i = 2; i <= 5; i++){
if ((i % 2) != 0){
for (sp = space; sp >= 1; sp--){
cout << " ";
}
for (j = 1; j <= i; j++){
cout << prt;
}
}
if ((i % 2) != 0) {
cout << "\n";
space--;
}
}
return 0;
} আউটপুট
$ $$$ $$$$$ $$$$$$$ $$$$$$$$$ $$$$$$$ $$$$$ $$$ $ $$$ $$$$$