Student Senior BlogBlogs

Triangle Pattern Printing in C (Beginner Friendly)

Sahil Verma
July 10, 2025
4 min read
#c programming#nested loops#number patterns#c language basics#for loop#beginner friendly#c programs for beginners
Banner for Triangle Pattern Printing in C (Beginner Friendly)

🧠 Why Pattern Printing?

Pattern problems are a great way to:

  • Practice nested loops
  • Improve your logic and dry-run skills
  • Prepare for coding interviews

In this guide, we’ll cover all the basic and common triangle patterns using simple C language code.


📌 Pattern 1: Left-Aligned Right-Angled Triangle

Output:

pattern
1* 2** 3*** 4**** 5*****
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 1; i <= 5; i++) { 5 for(int j = 1; j <= i; j++) { 6 printf("*"); 7 } 8 printf("\n"); 9 } 10 return 0; 11}

📌 Pattern 2: Right-Aligned Triangle

Output:

pattern
1 * 2 ** 3 *** 4 **** 5*****
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 1; i <= 5; i++) { 5 for(int j = 1; j <= 5 - i; j++) { 6 printf(" "); 7 } 8 for(int k = 1; k <= i; k++) { 9 printf("*"); 10 } 11 printf("\n"); 12 } 13 return 0; 14}

📌 Pattern 3: Inverted Left-Aligned Triangle

Output:

pattern
1***** 2**** 3*** 4** 5*
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 5; i >= 1; i--) { 5 for(int j = 1; j <= i; j++) { 6 printf("*"); 7 } 8 printf("\n"); 9 } 10 return 0; 11}

📌 Pattern 4: Inverted Right-Aligned Triangle

Output:

pattern
1***** 2 **** 3 *** 4 ** 5 *
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 5; i >= 1; i--) { 5 for(int j = 1; j <= 5 - i; j++) { 6 printf(" "); 7 } 8 for(int k = 1; k <= i; k++) { 9 printf("*"); 10 } 11 printf("\n"); 12 } 13 return 0; 14}

📌 Pattern 5: Full Pyramid

Output:

pattern
1 * 2 *** 3 ***** 4 ******* 5*********
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 1; i <= 5; i++) { 5 for(int j = 1; j <= 5 - i; j++) { 6 printf(" "); 7 } 8 for(int k = 1; k <= 2 * i - 1; k++) { 9 printf("*"); 10 } 11 printf("\n"); 12 } 13 return 0; 14}

📌 Pattern 6: Inverted Full Pyramid

Output:

pattern
1********* 2 ******* 3 ***** 4 *** 5 *
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 5; i >= 1; i--) { 5 for(int j = 1; j <= 5 - i; j++) { 6 printf(" "); 7 } 8 for(int k = 1; k <= 2 * i - 1; k++) { 9 printf("*"); 10 } 11 printf("\n"); 12 } 13 return 0; 14}

📌 Pattern 7: Number Triangle

Output:

pattern
11 212 3123 41234 512345
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 1; i <= 5; i++) { 5 for(int j = 1; j <= i; j++) { 6 printf("%d", j); 7 } 8 printf("\n"); 9 } 10 return 0; 11}

📌 Pattern 8: Row Number Repeated

Output:

pattern
11 222 3333 44444 555555
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 1; i <= 5; i++) { 5 for(int j = 1; j <= i; j++) { 6 printf("%d", i); 7 } 8 printf("\n"); 9 } 10 return 0; 11}

📌 Pattern 9: Inverted Number Triangle

Output:

pattern
112345 21234 3123 412 51
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 5; i >= 1; i--) { 5 for(int j = 1; j <= i; j++) { 6 printf("%d", j); 7 } 8 printf("\n"); 9 } 10 return 0; 11}

📌 Pattern 10: Right-Aligned Number Triangle

Output:

pattern
1 1 2 12 3 123 4 1234 512345
c
1#include <stdio.h> 2 3int main() { 4 for(int i = 1; i <= 5; i++) { 5 for(int j = 1; j <= 5 - i; j++) { 6 printf(" "); 7 } 8 for(int k = 1; k <= i; k++) { 9 printf("%d", k); 10 } 11 printf("\n"); 12 } 13 return 0; 14}

🚀 DO THIS YOURSELF: Practice Challenge

Try printing the following pattern on your own:

pattern
1 1 2 2 2 3 3 3 3 4 4 4 4 4 55 5 5 5 5

💡 Hints:

  • You need to handle both spaces and numbers
  • Each number is followed by a space: use printf("%d ", i);
  • Spaces = rows - i

🎯

Pattern questions build your logic muscle. Once you're confident with these, try:

  • Alphabet patterns
  • Hollow pyramids
  • Diamond shapes