Basic Square Incrementing Pattern
Program to Print Basic Square Incrementing Pattern
PRINTING PATTERN:
1111 2222 3333 4444
PREREQUISITE:
Basic knowledge of C language and loops.
ALGORITHM:
1. Take the number of rows (and columns, since it's a square) as input from the user and store it in a variable ('n').
2. Run a loop 'n' times to iterate through the rows (i=1 to i<=n).
3. For each row, run another loop 'n' times to print the current row number ('i').
4. Print the current row number ('i') for each column in that row.
5. Move to the next line after each row has been printed.
Code in C:
#include <stdio.h> int main() { int n, i, j; // Declaring integers for rows, columns, and loop counters printf("Enter the number of rows for the square incrementing pattern:\n"); scanf("%d", &n); // Taking input for number of rows // Loop to print the square incrementing pattern for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { printf("%d", i); // Printing the current row number } printf("\n"); // New line after each row } return 0; }
Output:
Enter the number of rows for the square incrementing pattern: 4 1111 2222 3333 4444