ধনাত্মক মান n দিয়ে দেওয়া হয়েছে এবং কাজটি হল ত্রিভুজাকার প্যাটার্ন তৈরি করা, অর্থাৎ মুদ্রিত সংখ্যাগুলির আয়না চিত্র এবং ফলাফল প্রদর্শন করা
উদাহরণ
Input-: n = 6 Output-:

Input-: n = 3 Output-:

নিম্নলিখিত প্রোগ্রামে ব্যবহৃত পদ্ধতি −
- ধনাত্মক পূর্ণসংখ্যা হিসাবে n এর মান ইনপুট করুন
- একটি প্যাটার্নে সারির সংখ্যার জন্য একটি লুপ i অতিক্রম করুন, অর্থাৎ n
- একটি প্যাটার্নে স্থান সংখ্যার জন্য একটি লুপ j অতিক্রম করুন
- একটি প্যাটার্নে অঙ্কের জন্য আরেকটি লুপ অতিক্রম করুন
অ্যালগরিদম
START Step 1-> declare function to print mirror image of triangular pattern void print_mirror(int n) declare and set int temp = 1 and temp2 = 1 Loop for int i = 0 and i < n and i++ Loop For int j = n - 1 and j > i and j— print space End Loop For int k = 1 and k <= temp and k++ print abs(k - temp2) End Set temp += 2 increment temp2++ print \n Step 2-> In main() Declare int n = 6 print_mirror(n) STOPঘোষণা করুন
উদাহরণ
#include <bits/stdc++.h>
using namespace std;
//function to print mirror image of triangular pattern
void print_mirror(int n) {
int temp = 1, temp2 = 1;
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
cout << " ";
}
for (int k = 1; k <= temp; k++) {
cout << abs(k - temp2);
}
temp += 2;
temp2++;
cout << "\n";
}
}
int main() {
int n = 6;
print_mirror(n);
return 0;
} আউটপুট
