Nested Loop Pattern Controller
C
Easy
3 views
Problem Description
Take row input from the user. Print a pattern using nested loops that increment the number of stars in each row. Then modify it to decrement it. Mastery of loop control.
Official Solution
#include <stdio.h>
int main() {
int rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
// Incrementing pattern
printf("nIncrementing Pattern:n");
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
printf("*");
}
printf("n");
}
// Decrementing pattern
printf("nDecrementing Pattern:n");
for (int i = rows; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
printf("*");
}
printf("n");
}
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!