Program to print the given pattern
12345
12345
12345
12345
12345
C Programming Language / Loop control in C Language
17407Program:
/** * C program to print number pattern * www.atnyla.com */ #include int main() { int rows, cols, i, j; /* Input rows and columns from user */ 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
Explanation:
Required knowledge
Basic C programming, Loop
Logic to print the given number pattern
Below is the step by step descriptive logic to print the given number pattern.
- Input number of rows and columns to print from user. Store it in some variable say rows and cols.
- Run an outer loop from 1 to rows. The loop structure should look like for(i=1; i<=rows; i++).
- Run an inner loop from 1 to cols. The loop structure should look like for(j=1; j<=cols; j++).
- Inside the inner loop print the current column number which is represented by j.
- Finally, after printing all columns of a row move to next line.
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.
# C Tutorials
# JAVA Tutorials
# HTML Tutorials
# Computer Fundamental
# Data Structure
# DBMS Tutorials
SQL
# C# Language
# R Language
# PHP
# Python
# Vue JS