Pattern programs can be a bit tricky to perform, but by applying simple logic related to the pattern, and using different concepts like a loop, you can easily create simple to complicated patterns.
C Program Pattern (1 12 123 1234 12345)
You can refer to the given video in order to have a practical and detailed explanation of this program with examples –
In this article, we are going to perform a simple C pattern program, where we will create the following pattern –
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
In the given video, you can find the detailed explanation along with the program, to create the above-given pattern.
Here is the program –
#include <stdio.h>
int main() {
int n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("n");
}
return 0;
}
Program output 1 –
Enter the number of rows: 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program Output 2 –
Enter the number of rows: 7
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7