C program pattern (1 23 456 78910)

Pattern programs can be a little bit tricky, but with proper knowledge, and simple logic for the pattern, you can simply create any pattern in C. Here is the pattern that we are going to create –

1
2 3
4 5 6
7 8 9 10

As you can see from the above pattern, it is a right-angle pattern, and in the nth row, there are n numbers. Also, we are printing a counter. For example, in the first row, we have 1 element, which is 1, and after that, we are increasing the counter.

In the given video, you can find the detailed explanation, and the program, to create the above pattern –

Here is the program for creating the above pattern –

#include <stdio.h>

int main() {
int rows, num = 1;

printf("Enter the number of rows: ");
scanf("%d", &rows);

for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
printf("%d ", num);
num++;
}
printf("n");
}

return 0;
}

Program Output 1 – 

Enter the number of rows: 4
1
2 3
4 5 6
7 8 9 10

Program output 2 – 

Enter the number of rows: 5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15