I'm trying to print an inverted pyramid(or triangle) with *, but when I run the following code it skips the for loop for i=rows, i.e. doesn't print any *,
the second iteration goes smoothly. I assume the problem is within while loop but I just don't see it clearly.
Here is the code:
#include <stdio.h>
int main() {
int k, i, space, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
printf("\n");
for (i = rows; i >= 1; i--, k = 0) {
for (space = 1; space <= rows - i; space++) {
printf(" ");
}
printf("smth");
while (k < 2 * i - 1) {
printf("* ");
k++;
}
printf("\n");
}
return 0;
}