In this tutorial, we are going to have a brief look at how to code All Number Patterns In C just by changing variable values using the SAME loop for all patterns. Check out the Star Patterns in C here.
This tutorial is very easy and interesting. I assure you that you will enjoy the whole tutorial on patterns.
To understand these patterns, you should have a good knowledge of C language Loops. So that you could easily grasp what is happening inside the Loops.
Point to Note:
The below patterns are obtained by just changing the variables in the Loops.
Small Note:
Loops play a key role in programming. If you try to understand patterns then you could easily master Loops. My suggestion to you is to practice and understand the patterns as many you can.
Coming to the concept, set the first one as your core pattern, and the rest are derived from it.
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i = rows
, 2. i >= 1
, 3. i--
Loop: #2 => 4. j = 1
, 5. j <= i
, 6. j++
,
Then print(j)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf( "%d", &rows );
for(i = rows; i >= 1; i--) {
for(j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 6
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Number Pattern: Half-Pyramid Pattern
Same Loop as above, but printing (i)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i = rows; i >= 1; i--) {
for(j = 1; j <= i; j++) {
printf("%d ", i);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 5
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i = rows
, 2. i >= 1
, 3. i--
Loop: #2 => 4. j = i
, 5. j >= 1
, 6. j--
Then print(j)
Code:
#include <stdio.h>
void main(){
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i = rows; i>=1; i--){
for(j = i; j>=1; j--){
printf("%d ", j);
}
printf( "\n" );
}
}
Output:
Enter Number Of Rows You Want: 6
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i = 1
, 2. i <= rows
, 3. i++
Loop: #2 => 4. j = rows
, 5. j >= 1
, 6. j--
Then print(j)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i = 1; i <= rows; i++) {
for(j = rows; j >= i; j--) {
printf("%d ", j);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 6
6 5 4 3 2 1
6 5 4 3 2
6 5 4 3
6 5 4
6 5
6
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i = 1
, 2. i <= rows
, 3. i++
Loop: #2 => 4. j = i
, 5. j <= rows
, 6. j++
Then print(j)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i=1; i<=rows; i++) {
for(j=i; j<=rows; j++) {
printf("%d ", j);
}
printf( "\n" );
}
}
Output:
Enter Number Of Rows You Want: 6
1 2 3 4 5 6
2 3 4 5 6
3 4 5 6
4 5 6
5 6
6
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i=1
, 2. i<=rows
, 3. i++
Loop: #2 => 4. j=1
, 5. j<=i
, 6. j++
Then print(j)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i=1; i<=rows; i++) {
for(j=1; j<=i; j++) {
printf("%d ", j);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 6
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i = rows
, 2. i >= 1
, 3. i--
Loop: #2 => 4. j = rows
, 5. j >= i
, 6. j--
Then print(j)
Code:
#include <stdio.h>
void main(){
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i=rows; i>=1; i--) {
for(j=rows; j>=i; j--) {
printf("%d ", j);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 6
6
6 5
6 5 4
6 5 4 3
6 5 4 3 2
6 5 4 3 2 1
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i=1
, 2. i <= rows
, 3. i++
Loop: #2 => 4. j=1
, 5. j <= i
, 6. j++
Then print(j)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i=1; i<=rows; i++) {
for(j=1; j<=i; j++) {
printf("%d ", j);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i=1
, 2. i <= rows
, 3. i++
Loop: #2 => 4. j=1
, 5. j <= i
, 6. j++
Then print(j)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i=1; i<=rows; i++) {
for(j=1; j<=i; j++) {
printf("%d ", i);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i=1
, 2. i<=rows
, 3. i++
Loop: #2 => 4. j=i
, 5. j<=rows
, 6. j++
Then print(j)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i=1; i<=rows; i++) {
for(j=i; j<=rows; j++) {
printf("%d ", j);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 5
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i=rows
, 2. i >= 1
, 3. i--
Loop: #2 => 4. j=rows
, 5. j >= 1
, 6. j--
Then print(j)
Code:
#include <stdio.h>
void main(){
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i=rows; i>=1; i--) {
for(j=rows; j>=i; j--) {
printf("%d ", j);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 5
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i=rows
, 2. i >= 1
, 3. i--
Loop: #2 => 4. j=rows
, 5. j >= i
, 6. j--
Then print(j)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i=rows; i>=1; i--) {
for(j=rows; j>=i; j--) {
printf("%d ", i);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 6
6
5 5
4 4 4
3 3 3 3
2 2 2 2 2
1 1 1 1 1 1
Number Pattern: Half-Pyramid Pattern
Loop: #1 => 1. i=1
, 2. i<=rows
, 3. i++
Loop: #2 => 4. j=i
, 5. j<=rows
, 6. j++
Then print(j)
Code:
#include <stdio.h>
void main() {
int rows, i, j;
printf("Enter Number Of Rows You Want: ");
scanf("%d", &rows);
for(i=1; i<=rows; i++) {
for(j=i; j<=rows; j++) {
printf("%d ", i);
}
printf("\n");
}
}
Output:
Enter Number Of Rows You Want: 6
1 1 1 1 1 1
2 2 2 2 2
3 3 3 3
4 4 4
5 5
6
Conclusion
Pheww! This is a brief view of 13 simple number patterns in C Programming language. If you have any doubts regarding the above patterns please comment below.
I hope that you enjoyed the post and learned about patterns implementation in c. If you feel that this post is useful, please share it with your friends and colleagues.
Thanks for reading it till the end.
Frequently Asked Questions(FAQs)
1. In C code, what are numerical patterns?
A number pattern is a set of numbers that are organized in a specific sequence to form a recognized shape or design.
2. Are these half-pyramid designs appropriate for newcomers?
Yes, these half-pyramid designs are basic and straightforward, making them an excellent place to begin learning C code.
3. Is there anything I need to make these half-pyramid patterns?
No, these patterns can be created with a simple text editor or an integrated development environment (IDE) that allows C code.
4. Can I alter these templates to make my own distinctive designs?
Yes, once you've grasped the reasoning behind these patterns, you can play around with various variants to create your own unique designs and patterns.
You may also like: