এই নিবন্ধটি C++ প্রোগ্রামিং ভাষা ব্যবহার করে একটি অর্ধ-পিরামিড প্যাটার্ন ব্যাশ প্রিন্ট করার উদ্দেশ্যে। প্রিন্ট করার জন্য নির্ধারিত প্যাটার্নের পরিপ্রেক্ষিতে, আমাদের লক্ষ্য অর্জনের জন্য নিম্নলিখিত অ্যালগরিদমটি সাজানো হচ্ছে;
অ্যালগরিদম
Step-1 Set the length of the Bash (Height) Step-2 Outer loop to handle the number of rows Step-3 Inner loop to handle columns Step-4 Print the pattern with the character (@) Step-5 Set the pointer to a new line after each row (outside the inner loop) Step-6 Repeat the loop till the Bash Height
উদাহরণ
সুতরাং, নিম্নলিখিত C++ সোর্স কোডটি শেষ পর্যন্ত পূর্বোক্ত অ্যালগরিদম অনুসরণ করে তৈরি করা হয়েছে;
#include <iostream>
using namespace std;
void PrintBash(int n){
// outer loop to handle number of rows
for (int i=0; i<n; i++){
// inner loop to handle number of columns
for(int j=0; j<=i; j++ ){
// printing character
cout << "@ ";
}
// ending line after each row
cout << endl;
}
}
int main(){
int Len = 6;
PrintBash(Len);
return 0;
} আউটপুট
উপরের কোডটি সংকলন করার পরে, অর্ধ-পিরামিডটি মুদ্রিত হবে এর মতো দেখায়।
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @