C
c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter number of rows: \n\n"); // Added a colon for better readability
if (scanf("%d", &rows) != 1) { // Check if scanf successfully read an integer
printf("Invalid input. Using default value.\n\n");
rows = 14; // Default value
}
// Removed the extra &; scanf needs the address of rows
for (i = 1; i <= rows; i++) {
// Corrected the inner loop condition for spaces
for (j = 1; j <= rows - i; j++) { // Print spaces before the asterisks to center the triangle
printf(" ");
}
// Corrected the loop for printing asterisks to create the desired pattern
for (j = 1; j <= i; j++) { // Print 'i' asterisks (i = current row number)
printf("* "); // Add a space after each asterisk for the pattern
}
printf("\n");
}
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run