Technology7 min read

Number Patterns: 13 Simple Half-Pyramid Patterns In C

Abhishek Ahlawat

By Abhishek Ahlawat โ€” Recently

Founder of StudyTonight and a MERN fullstack developer. Writes about JavaScript, web development, Linux, and tech.

Summarize this article using AI

In this tutorial, we are going to have a brief look on how to code 13 simple number patterns just by changing variables values using the SAME loop for all patterns in c language.

This tutorial is very easy and interesting. I assure that you will enjoy the whole tutorial on patterns.

simple number patterns in c

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:

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 rest are derived from it.


Half-Pyramid Pattern: Type #1

Loop: #1 => 1. i = rows, 2. i >= 1, 3. i--
Loop: #2 => 4. j = 1, 5. j <= i, 6. j++, printint(j)

#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


Half-Pyramid Pattern: Type #2

Same Loop as above, but printing (i)

#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


Half-Pyramid Pattern: Type #3

Loop: #1 => 1. i = rows, 2. i >= 1, 3. i--
Loop: #2 => 4. j = i, 5. j >= 1, 6. j--
then print (j)

#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


Half-Pyramid Pattern: Type #4

Loop: #1 => 1. i = 1, 2. i <= rows, 3. i++
Loop: #2 => 4. j = rows, 5. j >= 1, 6. j--
then printint ( j )

#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


Half-Pyramid Pattern: Type #5

Loop: #1 => 1. i = 1, 2. i <= rows, 3. i++
Loop: #2 => 4. j = i, 5. j <= rows, 6. j++
printint(j)

#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


Half-Pyramid Pattern: Type #6

Loop: #1 => 1. i=1, 2. i<=rows, 3. i++
Loop: #2 => 4. j=1, 5. j<=i, 6. j++
printint ( j )

#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


Half-Pyramid Pattern: Type #7

Loop: #1 => 1. i = rows, 2. i >= 1, 3. i--
Loop: #2 => 4. j = rows, 5. j >= i, 6. j--
print int(j)

#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


Half-Pyramid Pattern: Type #8

Loop: #1 => 1. i=1, 2. i <= rows, 3. i++
Loop: #2 => 4. j=1, 5. j <= i, 6. j++
print int(j)

#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


Half-Pyramid Pattern: Type #9

Loop: #1 => 1. i=1, 2. i <= rows, 3. i++
Loop: #2 => 4. j=1, 5. j <= i, 6. j++
printint(i)

#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


Half-Pyramid Pattern: Type #10

Loop: #1 => 1. i=1, 2. i<=rows, 3. i++
Loop: #2 => 4. j=i, 5. j<=rows, 6. j++
printint ( j )

#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


Half-Pyramid Pattern: Type #11

Loop: #1 => 1. i=rows, 2. i >= 1, 3. i--
Loop: #2 => 4. j=rows, 5. j >= 1, 6. j--
printint ( j )

#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


Half-Pyramid Pattern: Type #12

Loop: #1 => 1. i=rows, 2. i >= 1, 3. i--
Loop: #2 => 4. j=rows, 5. j >= i, 6. j--
printint ( i )

#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


Half-Pyramid Pattern: Type #13

Loop: #1 => 1. i=1, 2. i<=rows, 3. i++
Loop: #2 => 4. j=i, 5. j<=rows, 6. j++
printint ( i )

#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 language. If you have any doubts regarding 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.

You may also like:


Spotted something outdated or wrong?

Liked this? See more StudyTonight posts in Google results.

Add StudyTonight as a preferred source
Next questLIVE OPSStep 2 / 3

Practice real incidents in the browser

System Design Ops โ€” put out fires, ship fixes, and stack XP. Reading done. Time to play.

Play System Design
  • +XP

    Every sim

  • Incidents

    Live ops

  • Ranks

    Climb up

Read next