My issue
i didn’t understand what’s the error in this
My code
#include <iostream>
using namespace std;
void printPattern(int N) {
// Upper half
for (int i = N; i >= 1; --i) {
// Left stars
for (int j = 1; j <= i; ++j) {
cout << "*";
}
// Spaces
for (int j = 1; j <= 2 * (N - i); ++j) {
cout << " ";
}
// Right stars
for (int j = 1; j <= i; ++j) {
cout << "*";
}
cout << endl;
}
// Lower half
for (int i = 1; i <= N; ++i) {
// Left stars
for (int j = 1; j <= i; ++j) {
cout << "*";
}
// Spaces
for (int j = 1; j <= 2 * (N - i); ++j) {
cout << " ";
}
// Right stars
for (int j = 1; j <= i; ++j) {
cout << "*";
}
cout << endl;
}
}
int main() {
int N;
cin >> N; // Input the size of the pattern
printPattern(N); // Call the function to print the pattern
return 0;
}
Learning course: Learn Programming and Problem Solving using C++
Problem Link: https://www.codechef.com/learn/course/sit-cpp-fall/SITFALL64/problems/CPPFALL465