C program to Print Number Pattern 3

Write a C program to Print Number Pattern 3 with example. For this, we are going to use For Loop and While Loop.

C program to Print Number Pattern 3 using For Loop

This program allows the user to enter the maximum number of rows and columns he/she want to print as a rectangle. Next, compiler will print the numbers pattern.

```/* C program to Print Number Pattern 3 */

#include<stdio.h>

int main()
{
int i, j, rows, columns;

printf(" \nPlease Enter the Number of Rows : ");
scanf("%d", &rows);

printf(" \nPlease Enter the Number of Columns : ");
scanf("%d", &columns);

for(i = 1; i <= rows; i++)
{
for(j = i; j < i + columns; j++)
{
printf("%d", j);
}
printf("\n");
}
return 0;
}```

Let us see the Nested for loop

```for(i = 1; i <= rows; i++)
{
for(j = i; j <= i + columns; j++)
{
printf("%d", j);
}
printf("\n");
}```

Outer Loop – First Iteration

From the above C Programming screenshot you can observe that, The value of i is 5 and the condition (i <= 5) is True. So, it will enter into second for loop

Inner Loop – First Iteration

The j value is 1 and the condition (1 <= 6) is True. So, it will start executing the statements inside the loop.

`printf("%d", j);`

Next, we used the Increment Operator j++ to increment the J value by 1. This will happen until the condition inside the inner for loop fails. Next, iteration will start from beginning until both the Inner Loop and Outer loop conditions fails.

Program to Print Number Pattern 3 using while Loop

In this program we just replaced the For Loop with the While Loop. I suggest you to refer While Loop article to understand the logic.

```/* C program to Print Number Pattern 3 */

#include<stdio.h>

int main()
{
int i, j, rows, columns;

printf(" \nPlease Enter the Number of Rows : ");
scanf("%d", &rows);

printf(" \nPlease Enter the Number of Columns : ");
scanf("%d", &columns);

i = 1;

while(i <= rows)
{
j = i;

while(j < i + columns)
{
printf("%d", j);
j++;
}
i++;
printf("\n");
}
return 0;
}```
``````
Please Enter the Number of Rows : 5

Please Enter the Number of Columns : 6
123456
234567
345678
456789
5678910``````