Example:
Input rows: 5
Input columns: 5
Output:
Required knowledge
Basic C programming, LoopLogic to print the given number pattern
Before getting on this number pattern I highly recommend you to go through one of the previous number patterns to get yourself acquainted with the logic of number patterns.Now, once you are familiar with basic logic of printing number patterns you can easily get the logic of this pattern. If you look to the pattern carefully you will notice that for each column in each row the current column number gets printed.
Program to print the given number pattern
/** * C program to print number pattern */ #include <stdio.h> int main() { int rows, cols, i, j; /* * Reads number of rows, columns to be printed */ printf("Enter number of rows: "); scanf("%d", &rows); printf("Enter number of columns: "); scanf("%d", &cols); for(i=1; i<=rows; i++) { for(j=1; j<=cols; j++) { //Print the current column number printf("%d", j); } printf("\n"); } return 0; }
Output
Enter number of rows: 5
Enter number of columns: 5
12345
12345
12345
12345
12345
Enter number of columns: 5
12345
12345
12345
12345
12345
Screenshot
Happy coding ;)