My issue
pls explain what is wrong with my logic
My code
#include <stdio.h>
void printPattern(int n) {
for (int i = 1; i <= n; i++) {
// Print leading spaces
for (int j = 0; j < n - i; j++) {
printf(" ");
}
// Print stars with space, ensuring no trailing space in each line
for (int k = 0; k < i; k++) {
printf("*");
if (k != i - 1) {
printf(" ");
}
}
printf("\n");
}
}
int main() {
int n;
printf("Enter the number of rows: ");
scanf("%d", &n);
printPattern(n);
return 0;
}
Learning course: Roadmap to 3*
Problem Link: https://www.codechef.com/learn/course/klu-roadmap-3star/KLURMP300B/problems/LPYAS158